【发布时间】:2017-04-18 08:54:09
【问题描述】:
当我尝试使用 cmake 与 boost 链接以生成 Visual Studio 2015 文件时,cmake 会生成如下库路径:
optimized;D:/work/libs/boost_1_63_0/lib64-msvc-14.0/boost_regex-vc140-mt-1_63.lib;debug;D:/work/libs/boost_1_63_0/lib64-msvc-14.0/boost_regex-vc140-mt-gd-1_63.lib;[...]
但 Visual Studio 尝试将 libboost_regex-vc140-mt-gd-1_63.lib 与使用此路径的 cmake 文件生成的解决方案文件链接。
cmake文件的相关部分:
target_compile_definitions(${PROJECT_NAME} [...] BOOST_ALL_DYN_LINK)
message("${Boost_LIBRARIES}")
target_link_libraries(${PROJECT_NAME} ${Boost_LIBRARIES})
上面的optimized 和debug 路径来自这里的message(...) 命令,Visual Studio 输出是
2>LINK : fatal error LNK1104: cannot open file 'libboost_regex-vc140-mt-gd-1_63.lib'
哪个是正确的,因为它应该使用boost_regex-vc140-mt-gd-1_63.lib,这是${Boost_LIBRARIES}中的绝对路径。
奇怪的是,什么时候在find_package之前使用set(Boost_USE_STATIC_LIBS ON),问题恰恰相反,cmake找到libboost_文件,而VS期望boost_文件。
【问题讨论】:
-
libboost_regex-vc140-mt-gd-1_63.lib对应的是 boost::regex 的静态版本,我猜测 CMake 想要链接静态库。您可以尝试在您的 CMakeLists 中添加target_link_libraries(${PROJECT_NAME} Boost::dynamic_linking),或者在您的find_package(Boost))之前添加set(Boost_USE_STATIC_LIBS OFF)吗? -
我都添加了,但并没有改变错误。我认为当它按预期工作时,
$Boost_LIBRARIES应该包含libboost_regex-vc140-mt-gd-1_63.lib文件作为绝对路径,不是吗? -
您也可以从项目属性中查看 Visual Studio 解决方案想要链接的内容,至少应该以绝对路径的形式给出。
标签: visual-studio boost visual-studio-2015 cmake