[英]How to link boost using cmake on windows
StackOverFlow 社區!
我正在嘗試鏈接 boost 庫,但鏈接“boost_system”靜態庫時出錯。
我使用 cmake 2.8、MinGW 編譯器和 1.55.0 boost。
從日志來看,cmake 沒有看到通往庫的路徑。
這是錯誤:
Unable to find the requested Boost libraries.
Boost version: 1.55.0
Boost include path: c:/local/boost_1_55_0
Could not find the following static 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.
Call Stack (most recent call first):
這是cmake代碼:
cmake_minimum_required(VERSION 2.8)
project(test)
if (WIN32)
set(BOOST_ROOT "c:/local/boost_1_55_0")
set(BOOST_LIBRARYDIR ${BOOST_ROOT}/stage/lib/)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost 1.55 COMPONENTS system REQUIRED)
add_definitions(${Boost_LIB_DIAGNOSTIC_DEFINITIONS})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -static-libstdc++")
include_directories(${Boost_INCLUDE_DIR})
set(SOURCE_FILES main.cpp)
add_executable(test ${SOURCE_FILES})
target_link_libraries(test ${Boost_LIBRARIES})
endif (WIN32)
我收到這樣的帶有聲明集的日志(Boost_DETAILED_FAILURE_MSG on)
status** Boost Include: c:/local/boost_1_55_0
status** Boost Libraries:
status** Boost Libraries:
對我來說,設置提示變量CMAKE_INCLUDE_PATH
& CMAKE_LIBRARY_PATH
。 BOOST_ROOT
和BOOST_LIBRARYDIR
也不起作用。
另一個提示變量是Boost_COMPILER
、 Boost_NAMESPACE
、 Boost_ARCHITECTURE
它們有助於定義您的庫如何命名以提升搜索腳本。
使用SET(Boost_DEBUG 1)
幫助我診斷問題很多 - 因為它打印 Boost path suffixes= 和 _boost_LIBRARY_SEARCH_DIRS_RELEASE
例如
SET(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "D:/boost/boost_1_70_0")
SET(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "D:/boost/boost_1_70_0/stage/gcc/x64/lib")
SET(Boost_COMPILER ${Boost_COMPILER} "-mgw73")
SET(Boost_NAMESPACE ${Boost_NAMESPACE} "libboost")
SET(Boost_ARCHITECTURE "-x64")
或者
SET(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "D:/boost/boost_1_70_0")
SET(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "D:/boost/boost_1_70_0/stage/lib")
SET(Boost_COMPILER ${Boost_COMPILER} "-vc142")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.