在学习高博大佬的一起做RGB-D SLAM (3)时,编译库文件的过程中遇到了如下问题:
CMake Error at src/CMakeLists.txt:17 (TARGET_LINK_LIBRARIES):
Cannot specify link libraries for target "slambase" which is not built by
this project.
解决的方案是将:
ADD_LIBRARY( slambase slamBase.cpp )
TARGET_LINK_LIBRARIES( slambase
${OpenCV_LIBS}
${PCL_LIBRARIES} )
替换为:
add_library(slambase slamBase.cpp )
target_link_libraries(slambase ${OpenCV_LIBS} ${PCL_LIBS})
最终的CMakeLists.txt:
# 增加PCL库的依赖
FIND_PACKAGE( PCL REQUIRED COMPONENTS common io )
# 增加opencv的依赖
FIND_PACKAGE( OpenCV REQUIRED )
# 添加头文件和库文件
ADD_DEFINITIONS( ${PCL_DEFINITIONS} )
INCLUDE_DIRECTORIES( ${PCL_INCLUDE_DIRS} )
LINK_LIBRARIES( ${PCL_LIBRARY_DIRS} )
ADD_EXECUTABLE( generate_pointcloud generatePointCloud.cpp )
TARGET_LINK_LIBRARIES( generate_pointcloud ${OpenCV_LIBS}
${PCL_LIBRARIES} )
add_library(slambase slamBase.cpp )
target_link_libraries(slambase ${OpenCV_LIBS} ${PCL_LIBS})
编译之后结果: