visual-studio - CMake 不会将依赖库添加到项目文件中
问题描述
我正在使用 pcl 编写一个简单的示例代码,就像链接 http://pointclouds.org/documentation/tutorials/writing_pcd.php一样。
即使我点击链接,Visual Studio 也会报告链接错误。原因是 pcl 依赖于 boost 库,而 cmake 没有将 boost 库添加到 Visual Studio 的项目设置文件中。如果我使用以下行添加 boost 库,一切都会好起来的。
target_link_libraries(程序名 ${Boost_LIBRARIES})
为什么 CMake 不处理这个?有更好的解决方案吗?
CMake:3.13.2,
视觉工作室:社区 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})
解决方案
根据官方 repo 中的PCLConfig.cmake脚本,Boost 库被附加到PCL_LIBRARIES
变量中。(这是在脚本末尾附近执行的)。
因此,为了在使用 PCL 时自动链接 Boost 库,您需要使用PCL_LIBRARIES
变量进行链接,而不是PCL_<comp>_LIBRARIES
变量。
我不知道,给定的行为是否是有意的。如果您假设 Boost 库也应该是PCL_<comp>_LIBRARIES
变量的一部分,那么您可以填写一份关于此的错误报告。
推荐阅读
- apache-kafka - 用例:拥有大量订阅者的 Kafka 单一主题
- javascript - 当使用 Javascript 动态添加数据时,如何在 contenteditable div 的文本末尾获取插入符号位置?
- r - 在 r 程序中读取图像
- elasticsearch - filebeat 可以将日志行输出转换为 json 而无需在管道中使用 logstash?
- django - 为 Django URL 添加全局前缀
- c++ - 我在使用模算术解决问题时遇到问题
- security - Kubernetes 中的 RSA 私钥对攻击者来说有多大价值?
- python - 将函数的输出存储在 Django 中的另一个函数中
- python - 在测试用例的循环中不输入 x 的原因,显示“invalid literal for int() with base 10: '5 4 2 1'”
- c# - 模态窗口返回 null