當我嘗試使用cmake生成的Visual Studio 2015年文件與升壓鏈接,cmake的生成庫路徑是這樣的:與CMake和Visual Studio的鏈接助推2015年
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;[...]
但視覺工作室試圖鏈接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(...)
命令和視覺工作室輸出是
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)''之前設置(Boost_USE_STATIC_LIBS OFF)''? – oLen
我加了兩個,它不會改變錯誤。我認爲當它按預期工作時,''Boost_LIBRARIES''應該包含''libboost_regex-vc140-mt-gd-1_63.lib''文件作爲絕對路徑,不應該嗎? – allo
您還可以看看Visual Studio解決方案想要從項目屬性鏈接什麼,至少應該將其作爲絕對路徑給出。 – oLen