0
votes

I'm trying to link with the boost_system libraries for my Windows CMake project but keep getting the following error. I've tried several proposed solutions on similar questions but nothing seems to work.

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.

This is the current state of my cmake file (relevant to 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()
2
what compiler are you using? - J-Mik
Tried setting just BOOST_ROOT? - arrowd
@J-Mik I'm using MinGW as a compiler. - Gabriel Asman
@arrowd I already tried - Gabriel Asman
@Gabriel-Asman the answer I posted works for MinGW, MSVC and Linux. let me know if you're having a problem witth it. - J-Mik

2 Answers

2
votes

Here's how I use it portably, but you need to specify the components you need:

First you need to build the library. Open a command prompt in windows and type in this: (you need to specify the /bin/ folder of your MinGW installation folder, so modify the first line accordingly)

PATH=C:\MinGW\bin;%PATH%
cd C:/Program Files/boost_1_60_0/
bootstrap.bat 
b2 --toolset=gcc link=static --build-type=complete

It should take a couple of minutes to compile. Then in your CMakeLists.txt add:

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()
0
votes

You are using the wrong variable name. It should be

SET(BOOST_INCLUDEDIR "C:/Program Files/boost_1_60_0")

Mind the missing plural-s. See also https://cmake.org/cmake/help/v3.5/module/FindBoost.html

By the way, you should not set it that way, but add C:/Program Files/boost_1_60_0 to CMAKE_PREFIX_PATH and pass that to your cmake call.