查看头文件后发现,头文件里又引入了多个头文件,所以单独引入头文件应该是很困难的,这里需要考虑加入库。那么库如何寻找呢?
PROJECT(CGITS)
cmake_minimum_required(VERSION 2.8)
SET(CMAKE_C_COMPILER g++)
add_compile_options(-std=c++11)
FIND_PACKAGE(VTK)
IF(NOT VTK_DIR)
MESSAGE(FATAL_ERROR "Please set VTK_DIR.")
ENDIF(NOT VTK_DIR)
INCLUDE(${VTK_USE_FILE})
FIND_PACKAGE(IGSTK)
IF(IGSTK_FOUND)
INCLUDE_DIRECTORIES(${IGSTK_INCLUDE_DIR})
ENDIF(IGSTK_FOUND)
FIND_PACKAGE(ITK)
IF(NOT ITK_DIR)
MESSAGE(FATAL_ERROR "Please set ITK_DIR.")
ENDIF(NOT ITK_DIR)
IF(ITK_FOUND)
INCLUDE(${ITK_USE_FILE})
ENDIF(ITK_FOUND)
LINK_DIRECTORIES (
${IGSTK_DIR}/bin/Debug
${VTK_DIR}/bin/Debug
${ITK_DIR}/bin/Debug
${FLTK_DIR}/bin/Debug
)
INCLUDE_DIRECTORIES (
${IGSTK_DIR}
${IGSTK_SOURCE_DIR}/Source
${IGSTK_SOURCE_DIR}/Utilities/SceneGraphVisualization
${IGSTK_SOURCE_DIR}/Examples/TrackerConfiguration
${IGSTK_SOURCE_DIR}/Examples/TransformReaders
${IGSTK_SOURCE_DIR}/Examples/TrackerConfiguration/configurationFileReaders
${IGSTK_SOURCE_DIR}/Examples/Tools
${ITK_SOURCE_DIR}/Wrapping/WrapITK/ExternalProjects/ItkVtkGlue/src
)
IF(VTK_MFC_DELAYLOAD_VTK_DLLS)
VTK_MFC_ADD_DELAYLOAD_FLAGS(CMAKE_EXE_LINKER_FLAGS
vtkMFC.dll
vtkRendering.dll
vtkIO.dll
vtkFiltering.dll
vtkCommon.dll
)
ENDIF(VTK_MFC_DELAYLOAD_VTK_DLLS)
SET( CGITS_SRCS
ArchiveDlg
AuroraTrackerAndSerialComm
AffectiveMeshReader
AutoPair
AffectiveZoneImageReader.txx
BaseObject
CaptureWIN
CGITS
CGITS.rc
CGITSDlg
CLBTDlg
DirObject
DiscFormatData
DiscFormatDataEvent
DiscMaster
DiscRecorder
DottedLineObjectRepresentation
FileListBox
FileObject
Grid
igstkCustomCrossHairObjectRepresentation
igstkCustomDottedLineObjectRepresentation
igstkCustomLineObjectRepresentation
igstkMyImageResliceObjectRepresentation
igstkMyReslicerPlaneSpatialObject
igstkTreatmentPlan
igstkTreatmentPlanIO
igstkYHImageResliceObjectRepresentation
igstkYHReslicerPlaneSpatialObject
igstkZoneImageResliceObjectRepresentation
MainDlg
MSSDlg
MultilineList
MyAuroraTracker
P4Dlg
PlanDlg
ZoneMesh
resource
res/CGITS.rc2
SYSTEMDlg
StdAfx
TimeCompute
targetver
)
ADD_EXECUTABLE(CGITS WIN32 ${CGITS_SRCS})
IF(VTK_MFC_EXTRA_LIBS)
TARGET_LINK_LIBRARIES(CGITS ${VTK_MFC_EXTRA_LIBS})
ENDIF(VTK_MFC_EXTRA_LIBS)
TARGET_LINK_LIBRARIES(CGITS vtkMFC ITKBasicFilters ITKNumerics ITKCommon ITKIO TrackerConfiguration TransformReaders Tools IGSTK igstkWINWidget winmm)
现在有个问题就是,用的库是老旧版本,但是配vs2019,我考虑用高版本的CMake试试:
额外增加了两句以支持C++11
放进相应的文件路径:
现在放进CMake文件了,讲道理它会自己寻找吧,但是原项目中这个路径还有一堆相关的库里面的头文件啥的。现在不添加先试试。。。。
CMake Warning at CMakeLists.txt:6 (FIND_PACKAGE):
By not providing "FindVTK.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "VTK", but
CMake did not find one.
Could not find a package configuration file provided by "VTK" with any of
the following names:
VTKConfig.cmake
vtk-config.cmake
Add the installation prefix of "VTK" to CMAKE_PREFIX_PATH or set "VTK_DIR"
to a directory containing one of the above files. If "VTK" provides a
separate development package or SDK, be sure it has been installed.
CMake Error at CMakeLists.txt:8 (MESSAGE):
Please set VTK_DIR.
还是没找到CMake,这里我添加它的绝对路径。然后继续报错:
CMake Warning at CMakeLists.txt:12 (FIND_PACKAGE):
By not providing "FindIGSTK.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "IGSTK", but
CMake did not find one.
Could not find a package configuration file provided by "IGSTK" with any of
the following names:
IGSTKConfig.cmake
igstk-config.cmake
Add the installation prefix of "IGSTK" to CMAKE_PREFIX_PATH or set
"IGSTK_DIR" to a directory containing one of the above files. If "IGSTK"
provides a separate development package or SDK, be sure it has been
installed.
CMake Warning at CMakeLists.txt:17 (FIND_PACKAGE):
By not providing "FindITK.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "ITK", but
CMake did not find one.
Could not find a package configuration file provided by "ITK" with any of
the following names:
ITKConfig.cmake
itk-config.cmake
Add the installation prefix of "ITK" to CMAKE_PREFIX_PATH or set "ITK_DIR"
to a directory containing one of the above files. If "ITK" provides a
separate development package or SDK, be sure it has been installed.
CMake Error at CMakeLists.txt:19 (MESSAGE):
Please set ITK_DIR.
继续添加IGSTK和ITK的绝对路径,配置完成:
生成失败:
Configuring done
CMake Error at CMakeLists.txt:100 (ADD_EXECUTABLE):
Cannot find source file:
ArchiveDlg
Tried extensions .c .C .c++ .cc .cpp .cxx .cu .m .M .mm .h .hh .h++ .hm
.hpp .hxx .in .txx
CMake Error at CMakeLists.txt:100 (ADD_EXECUTABLE):
No SOURCES given to target: CGITS
这意思是后面的没找到资源丫,这个资源应该是放到CMakelist下面的。现在添加一下,不过存在的问题是,有几个资源应该是应用的对话框相关程序,这些我们还没有做,怎么办呢?
现在又思考了一下,这个CMake的目的可能是为最后的整个文件准备的,不是现在用的,那现在咋整呢。。。
添加文件引用的lib静态库路径:工程—属性—配置属性—链接器—常规—附加库目录:加上lib文件存放目录。
已经包含了,编译并没有改善。那现在准备先编写好APP.h和.cpp,有不用的地方先注释掉,先看看能不能用那些头文件啥的:
结果是没有找到该文件,现在考虑把.h文件添加到CGIT的文件目录下,仍然无效,直接删了,不如直接包含原代码的位置:
突然发现之前的操作应该是连锁的三步,而不是其中的某一个:
这里听到航哥的建议,VS中打开属性管理器,在DebugWIn32中新建一个,可以在这里配置以上的属性:
这样的配置方法是在自己的电脑环境上是一劳永逸的。方法见这里
1.win32新建属性:
2.放头文件路径,这里我直接放了个bin的大路径:
3.链接器-输入放 lib 路径,现在问题来了,我怎么知道有哪些lib,原项目找不到啊…:
先加一个VTK之前文件里手动配置的附加库依赖项试试。。。报错好像减少了!!!!
继续找ITK的试试:找不到啊…我也只记得VTK用了很多lib,ITK 没有这操作啊?
现在突然有些担心,因为自己使用的是旧版本的ITK、VTK,而且环境应该是32位的,虽然VS2019这里也 是显示的32位。
再试试吧:从IGSTK bin debug文件里看到的lib,添加:
IGSTK.lib
igstkStateMachineExportTest.lib
igstkTests.lib
SceneGraphVisualization.lib
Tools.lib
TrackerConfiguration.lib
TransformReaders.lib
TransformWriters.lib
再添加ITK的:
shell32.lib
ole32.lib
oleaut32.lib
uuid.lib
comdlg32.lib
advapi32.lib
…\bin\Debug\vtkCommon.lib
…\bin\Debug\vtksys.lib
ws2_32.lib
wsock32.lib
IGSTK.lib
igstkStateMachineExportTest.lib
igstkTests.lib
SceneGraphVisualization.lib
Tools.lib
TrackerConfiguration.lib
TransformReaders.lib
TransformWriters.lib
ITKFEM.lib
itkTestDriver.lib
ITKIO.lib
ITKAlgorithms.lib
ITKNumerics.lib
ITKBasicFilters.lib
ITKSpatialObject.lib
ITKStatistics.lib
ITKCommon.lib
itkvnl_inst.lib
itkvnl_algo.lib
itkvnl.lib
itkgdcm.lib
ITKMetaIO.lib
itktiff.lib
itkNetlibSlatec.lib
ITKNrrdIO.lib
itkpng.lib
itkv3p_netlib.lib
ITKniftiio.lib
itkopenjpeg.lib
itkzlib.lib
ITKznz.lib
itksys.lib
ITKDICOMParser.lib
itktestlib.lib
itkjpeg16.lib
itkjpeg8.lib
ITKEXPAT.lib
itkjpeg12.lib
itkvcl.lib
itkv3p_lsqr.lib
无法识别,凉凉。
该项目到此告一段落,我觉着最好是先熟悉其操作。
现在的目标是,自己新建一个sln项目,然后用VTK的库,实现一个小例子。
我最后又进行了一次尝试,选用此版本CMake,搭配vs2019,并在configure时确定生成相应的win32.
手动添加了各库的路径
generate失败后,把原项目的.h.cpp都复制到新项目路径:
竟然generate成功,这里看看生成的bin里怎么样了- -
放弃了。