[英]CMake link with Boost Libraries
我正在嘗試與Windows CMake項目的boost_system庫鏈接,但始終收到以下錯誤。 我已經針對類似的問題嘗試了幾種建議的解決方案,但似乎無濟於事。
Error:Unable to find the requested Boost libraries.
Boost version: 1.60.0
Boost include path: C:/Program Files/boost_1_60_0
Could not find the following Boost libraries:
boost_system
No Boost libraries were found. You may need to set BOOST_LIBRARYDIR to the
directory containing Boost libraries or BOOST_ROOT to the location of Boost.
這是我的cmake文件的當前狀態(與boost有關)
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
SET(BOOST_INCLUDEDIRS "C:/Program Files/boost_1_60_0")
SET(BOOST_LIBRARYDIR "C:/Program Files/boost_1_60_0/lib")
find_package(Boost 1.60.0 COMPONENTS system REQUIRED)
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
endif()
這是我可移植使用的方式,但是您需要指定所需的組件:
首先,您需要構建庫。 在Windows中打開命令提示符並鍵入以下內容:(您需要指定MinGW安裝文件夾的/ bin /文件夾,因此請相應地修改第一行)
PATH=C:\MinGW\bin;%PATH%
cd C:/Program Files/boost_1_60_0/
bootstrap.bat
b2 --toolset=gcc link=static --build-type=complete
編譯需要花費幾分鍾。 然后在您的CMakeLists.txt中添加:
if (WIN32)
set(BOOST_ROOT C:/Program Files/boost_1_60_0/)
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
include_directories(${BOOST_ROOT})
link_directories(${BOOST_ROOT}/stage/lib) # add this before add_executable()
endif()
# Here add your add_executable function
add_executable(your_exec ${SOURCE_FILES} ${INCLUDE_FILES})
if(NOT MSVC)
find_package(Boost REQUIRED COMPONENTS date_time filesystem wserialization system serialization thread regex)
if (Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
target_link_libraries(your_exec ${Boost_LIBRARIES})
endif()
endif()
您使用了錯誤的變量名。 它應該是
SET(BOOST_INCLUDEDIR "C:/Program Files/boost_1_60_0")
注意缺失的復數-s。 另請參閱https://cmake.org/cmake/help/v3.5/module/FindBoost.html
順便說一句,您不應該這樣設置,而是將C:/Program Files/boost_1_60_0
到CMAKE_PREFIX_PATH
並將其傳遞給cmake調用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.