CMake和链接库出错

时间:2013-11-08 09:26:39

标签: c++ cmake

我有一个项目使用ITKVTK库以及一个CMakeLists文件,我可以用它来生成我的项目。我现在正在尝试使用新的库(VMTK)。它附带了CMake使用文件,我在CMakeLists中包含该文件以导入源和库。我遇到的问题是它没有正确生成到库的正确路径。当我尝试编译项目时出现以下错误:

Creating library C:/itkProjects/repository/ITK_source/vmtk/vmtkcenterline/source/build/Debug/vmtkcenterline.lib and object C:/itkProjects/repository/ITK_source/vmtk/vmtkcenterline/source/build/Debug/vmtkcenterline.exp
2>vmtkcenterline.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static class vtkvmtkCapPolyData * __cdecl vtkvmtkCapPolyData::New(void)" (__imp_?New@vtkvmtkCapPolyData@@SAPAV1@XZ) referenced in function "public: static class vtkSmartPointer<class vtkvmtkCapPolyData> __cdecl vtkSmartPointer<class vtkvmtkCapPolyData>::New(void)" (?New@?$vtkSmartPointer@VvtkvmtkCapPolyData@@@@SA?AV1@XZ)
2>C:\itkProjects\repository\ITK_source\vmtk\vmtkcenterline\source\build\Debug\vmtkcenterline.exe : fatal error LNK1120: 1 unresolved externals

CMake使用文件应包含库。这个 usefile 粘贴在下面:

INCLUDE(CMakeImportBuildSettings)

SET (VMTK_CPP_SOURCE_DIRS "C:/vmtk/source/vtkVmtk")

SET(VMTK_INCLUDE_DIRS
  ${VMTK_CPP_SOURCE_DIRS}
  ${VMTK_CPP_SOURCE_DIRS}/Common
  ${VMTK_CPP_SOURCE_DIRS}/ComputationalGeometry
  ${VMTK_CPP_SOURCE_DIRS}/Contrib
  ${VMTK_CPP_SOURCE_DIRS}/DifferentialGeometry
  ${VMTK_CPP_SOURCE_DIRS}/IO
  ${VMTK_CPP_SOURCE_DIRS}/Misc
  ${VMTK_CPP_SOURCE_DIRS}/Segmentation
  "C:/vmtk/build/VMTK-Build"
  "C:/vmtk/build/VMTK-Build/vtkVmtk"
  "C:/vmtk/build/Install/include/vmtk"
  "C:/vmtk/build/VMTK-Build/bin/Debug"
)

INCLUDE(
  "C:/vmtk/build/VMTK-Build/VMTKLibraryDepends.cmake"
)

SET(VMTK_LIBRARY_DIRS "C:/vmtk/build/VMTK-Build/bin")

SET(VMTK_USE_FILE
  "C:/vmtk/build/VMTK-Build/VMTKUse.cmake"
)

INCLUDE_DIRECTORIES(${VMTK_INCLUDE_DIRS})

LINK_DIRECTORIES(${VMTK_LIBRARY_DIRS})

LINK_LIBRARIES(vtkvmtkCommon vtkvmtkComputationalGeometry vtkvmtkContrib vtkvmtkDifferentialGeometry vtkvmtkIO vtkvmtkITK vtkvmtkMisc vtkvmtkSegmentation nl tet)

如何正确包含库?图书馆的直接途径是:

C:\vmtk\build\VMTK-Build\bin\Debug 

我可以直接设置它们的路径吗?

PS:如果CMakeListshere.

有帮助

1 个答案:

答案 0 :(得分:0)

我不知道这是否仍然是一个问题,但我遇到了同样的问题...... CMake没有链接到库(在我的情况下来自ITK)。要解决,我补充道:

link_directories(/usr/local/lib)
target_link_libraries(myApp ITKSys-4.7 ITKCommon-4.7)

这似乎可以解决问题。