简体   繁体   中英

How to link boost using cmake on windows

the StackOverFlow community!

I'm trying to link up boost libraries and there's an error of linking up the 'boost_system' static library.
I use cmake 2.8, the MinGW compiler and the 1.55.0 boost.
Judging by the logs, cmake doesn't see the pathway to the libraries.


Here's the error:

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):


Here's the cmake code:

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)

I receive logs like this with the declared set(Boost_DETAILED_FAILURE_MSG on)

status** Boost Include: c:/local/boost_1_55_0
status** Boost Libraries: 
status** Boost Libraries: 

For me worked setting hint variables CMAKE_INCLUDE_PATH & CMAKE_LIBRARY_PATH . BOOST_ROOT & BOOST_LIBRARYDIR were not working also.

Another hint variables are Boost_COMPILER , Boost_NAMESPACE , Boost_ARCHITECTURE they help to define how your library is named to boost search script.

Using SET(Boost_DEBUG 1) helped me a lot do diagnose a problem -as it prints Boost path suffixes= and _boost_LIBRARY_SEARCH_DIRS_RELEASE

For example

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")

Or

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")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM