0

For the past few days I have been struggling to get the Boost libraries included in my project. I have been reading and using suggestions made by numerous posters on Stack Overflow and for some reason that I don't understand I still cannot get CMake to find Boost, or if it does find Boost, I can't compile because it can't find the boost_system library that I apparently need to link with to remove the system config() not found error.

I am currently working on Windows 10 with the MinGW Implementation of the GNU C++ Compiler v4.9.3-1

Boost is currently extracted on my system here:

C:\boost_1_60_0

This is what my CMake file currently looks like:

cmake_minimum_required(VERSION 3.5)
project(Engine)

#SET(GCC_COVERAGE_LINK_FLAGS "-lboost_system")

message(STATUS "start running cmake...")

SET(BOOSTROOT "C:/boost_1_60_0/")
SET(BOOST_ROOT "C:/boost_1_60_0/")
SET(BOOST_LIBRARYDIR "C:/boost_1_60_0/libs/")

find_package(Boost 1.60.0 COMPONENTS system REQUIRED)

if(Boost_FOUND)

    message(STATUS "Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}")
    message(STATUS "Boost_LIBRARIES: ${Boost_LIBRARIES}")
    message(STATUS "Boost_VERSION: ${Boost_VERSION}")

    include_directories(${Boost_INCLUDE_DIRS})
    add_definitions("-DHAS_BOOST")

endif()

add_executable(Engine main.cpp)

if(Boost_FOUND)

    target_link_libraries(Engine ${Boost_LIBRARIES})

endif()

set(SOURCE_FILES main.cpp)

The Error that I am currently getting is:

Error:Unable to find the requested Boost libraries.
Boost version: 1.60.0
Boost include path: C:/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.

** UPDATE ** This is the output when running cmake with -DBoost_Debug=ON:

_boost_TEST_VERSIONS = 1.61.0;1.61;1.60.0;1.60
Boost_USE_MULTITHREADED = TRUE
Boost_USE_STATIC_LIBS = 
Boost_USE_STATIC_RUNTIME = 
Boost_ADDITIONAL_VERSIONS = 
Boost_NO_SYSTEM_PATHS = 
Declared as CMake or Environmental Variables:
 BOOST_ROOT = C:/boost_1_60_0/
 BOOST_INCLUDEDIR = 
 BOOST_LIBRARYDIR = C:/boost_1_60_0/libs/
_boost_TEST_VERSIONS = 1.61.0;1.61;1.60.0;1.60
location of version.hpp: C:/boost_1_60_0/boost/version.hpp
version.hpp reveals boost 1.60.0
guessed _boost_COMPILER = -mgw49
_boost_MULTITHREADED = -mt
_boost_RELEASE_ABI_TAG = -
_boost_DEBUG_ABI_TAG = -d
_boost_LIBRARY_SEARCH_DIRS_RELEASE = C:/boost_1_60_0/libs/;C:/boost_1_60_0//lib;C:/boost_1_60_0//stage/lib;C:/boost_1_60_0/lib;C:/boost_1_60_0/../lib;C:/boost_1_60_0/stage/lib;PATHS;C:/boost/lib;C:/boost;/sw/local/lib_boost_LIBRARY_SEARCH_DIRS_DEBUG   = C:/boost_1_60_0/libs/;C:/boost_1_60_0//lib;C:/boost_1_60_0//stage/lib;C:/boost_1_60_0/lib;C:/boost_1_60_0/../lib;C:/boost_1_60_0/stage/lib;PATHS;C:/boost/lib;C:/boost;/sw/local/lib
Searching for SYSTEM_LIBRARY_RELEASE: boost_system-mgw49-mt-1_60;boost_system-mgw49-mt;boost_system-mt-1_60;boost_system-mt;boost_system
Searching for SYSTEM_LIBRARY_DEBUG: boost_system-mgw49-mt-d-1_60;boost_system-mgw49-mt-d;boost_system-mt-d-1_60;boost_system-mt-d;boost_system-mt;boost_system

Thanks in advance

Richard
  • 457
  • 1
  • 6
  • 21
  • 1
    Try re-running with -DBoost_DEBUG=ON? Also, maybe you'll find an answer here: http://stackoverflow.com/questions/13280823/cmake-not-finding-boost –  Apr 01 '16 at 18:40
  • I am not sure where to set or how to run it with -DBoost_DEBUG=ON. Nevermind I figured it out, update above – Richard Apr 01 '16 at 18:45
  • 1
    Try searching for file that starts with "libboost_system" in C:/boost_1_60_0/ and checking that it is located in _boost_LIBRARY_SEARCH_DIRS_RELEASE or _boost_LIBRARY_SEARCH_DIRS_DEBUG? –  Apr 01 '16 at 19:12
  • I found a few of them, they are located in C:\boost_1_60_\stage\lib and the rest under C:\boost_1_60_0\bin.v2\libs\system\build\msvc-14.0\debug\link-static\threading-multi – Richard Apr 01 '16 at 21:00

1 Answers1

1

There are some useful flags to help FindBoost to find libraries.

Try setting these variables (on or off - it depends on your boost installation) before calling find_package(Boost)

set(Boost_LIB_PREFIX            "lib"       CACHE STRING "")
set(Boost_USE_MULTITHREADED     ON          CACHE BOOL "") # '-mt' flag
set(Boost_USE_STATIC_LIBS       ON          CACHE BOOL "")
set(Boost_USE_STATIC_RUNTIME    ON          CACHE BOOL "") # '-s' tag
set(Boost_USE_DEBUG_RUNTIME     ON          CACHE BOOL "") # '-g' tag
set(Boost_COMPILER              "-mgw49"    CACHE STRING "")

Setting a flag with set(Boost_DETAILED_FAILURE_MSG TRUE) will greatly help you in diagnostics

  • It now says Boost_DIR - Boost_DIR-NOTFOUND, I tried setting it like this SET(BOOST_DIR "C:/boost_1_60_0/"). Still didn't find it. It also can't find Boost_SYSTEM_LIBRARY_DEBUG or Boost_SYSTEM_LIBRARY_RELEASE – Richard Apr 01 '16 at 21:16
  • There's one important thing more. Did you compile your boost with mingw? I've noticed that you have 'msvc-14.0' in your library paths. Building the boost with the same mingw is important, even if cmake will find the libraries, mingw will fail the linking stage. I've checked my project's cmake cache - and there's Boost_DIR-NOTFOUND too, but both the includes directory and all of the libraries are found correctly. – Philipp Davies Apr 01 '16 at 22:09
  • I realised I had made a really big mistake with regards to the compilation. I recompiled everything now with the MinGW Compiler. I have never had to build libs before and I just ran the bat file and it used the msvc++ compiler as I have both MinGW and MSVC installed on my system...I apologise for wasting your time. – Richard Apr 01 '16 at 23:35