CMake不会将依赖库添加到项目文件

时间:2019-01-31 06:47:38

标签: visual-studio boost cmake

我正在使用pcl作为链接编写一个简单的示例代码 http://pointclouds.org/documentation/tutorials/writing_pcd.php

即使我点击了链接,Visual Studio也会报告链接错误。 原因是pcl依赖于boost库,而cmake不依赖 将boost库添加到Visual Studio的项目设置文件中。 如果我在下面的行中添加boost库,一切都会好的。

target_link_libraries(progname $ {Boost_LIBRARIES})

为什么CMake无法处理此问题?有更好的解决方案吗?

CMake:3.13.2,

Visual Studio:社区2017

PCL:PCL-1.9.1-AllInOne-msvc2017-win64.exe

编辑: CMakeLists.txt

cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
project(MY_GRAND_PROJECT)
set(Boost_DEBUG ON)

set(Boost_USE_STATIC_LIBS OFF) 
set(Boost_USE_MULTITHREADED ON)  
set(Boost_USE_STATIC_RUNTIME OFF) 
find_package(Boost 1.45.0) 

find_package(PCL 1.9.1 REQUIRED COMPONENTS common io)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
add_executable(pcd_write_test pcd_write.cpp)
target_link_libraries(pcd_write_test ${PCL_COMMON_LIBRARIES} ${PCL_IO_LIBRARIES}  ${Boost_LIBRARIES})

1 个答案:

答案 0 :(得分:0)

按照PCLConfig.cmake在官方回购脚本,Boost库被附加在PCL_LIBRARIES变量。 (这是在脚本结尾处执行的。)

因此,对于包含Boost库自动链接时使用PCL,则需要使用PCL_LIBRARIES用于连接,而不是PCL_<comp>_LIBRARIES变量变量。


我不知道给定的行为是否故意。如果您假设Boost库也应该是PCL_<comp>_LIBRARIES变量的一部分,那么您可以填写有关该错误的报告。