1
votes

The root directory of boost ($ENV{BOOST_ROOT}) is

C:\Boost\boost_1_64_0

All compiled libraries (.dll, .lib) are in

C:\Boost\boost_1_64_0\lib64-msvc-14.1

They have both boost_xxx and libboost_xxx.

My cmake file is

set(BOOST_ROOT "$ENV{BOOST_ROOT}") 
set(BOOST_LIBRARYDIR "$ENV{BOOST_ROOT}/lib64-msvc-14.1")

message("${BOOST_ROOT}")
message("${BOOST_LIBRARYDIR}")
message("${Boost_INCLUDE_DIR}")

if(MSVC)
    add_definitions(-DBOOST_ALL_NO_LIB) 
    add_definitions(-DBOOST_ALL_DYN_LINK)
endif()

find_package(Boost 1.64.0 COMPONENTS system filesystem program_options REQUIRED)

And the output is

C:\Boost\boost_1_64_0

C:\Boost\boost_1_64_0/lib64-msvc-14.1

C:/Boost/boost_1_64_0

CMake Error at C:/Program Files/CMake/share/cmake-3.8/Modules/FindBoost.cmake:1842 (message):
Unable to find the requested Boost libraries.

Boost version: 1.64.0

Boost include path: C:/Boost/boost_1_64_0

Could not find the following Boost libraries:

      boost_system
      boost_filesystem
      boost_program_options

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):
CMakeLists.txt:78 (find_package)

CMake Error at CMakeLists.txt:84 (message): Boost not found

Could someone help please? I have spent hours on this but couldn't figure out why this doesn't work.

3
Setting BOOST_DEBUG is exactly for debugging such cases. Do that and show the resulted log.Tsyvarev

3 Answers

0
votes

First of all, what CMake version do you use? Recently a regression fix was included into 3.8.1 release -- it was about backslashes in BOOST_ROOT.

Secondly, you don't need to specify anything else ('cept maybe the BOOST_ROOT) if you are using official prebuilt Windows binaries -- FindBoost.cmake would try to find them as well. (Unfortunately I can't recall since what version.)

Never do set(BOOST_ROOT...) in your CMakeLists.txt -- just pass this parameter to cmake run via -D option. A better way is the following:

if(NOT DEFINED BOOST_ROOT AND NOT "${ENV{BOOST_ROOT}" STREQUAL "")
    set(BOOST_ROOT "$ENV{BOOST_ROOT}")
endif()

Use imported targets to link w/ needed Boost libraries and to modify compile/linker flags per taget. Please avoid to modify "global" compiler/linker options -- i.e. use corresponding target_xxx commands instead of add_definitions & etc.

0
votes

I use the following script to load boost with CMake (working with Linux and Windows) :

set(BoostPath "${DefaultBoostPath}" CACHE PATH "Path to Boost")
message(STATUS "Path to Boost: ${BoostPath}")
set(BOOST_ROOT "${BoostPath}")
set(Boost_USE_MULTITHREAD ON)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_NO_SYSTEM_PATHS ON)
set(Boost_ADDITIONAL_VERSIONS "1.57.0" "1.57" "1.58.0" "1.58" "1.59.0" "1.59" "1.60.0" "1.60" "1.61.0" "1.61" "1.62.0" "1.62" "1.63.0" "1.63" "1.64.0" "1.64")
find_package(Boost ${RequiredBoostVersion} REQUIRED COMPONENTS ${RequiredBoostComponents})
mark_as_advanced(FORCE Boost_DIR)
set(BoostVersion "${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION}")
message(STATUS "Boost version: ${BoostVersion}")
if(CompilerName STREQUAL "gcc")
    set(System_LIBRARIES ${System_LIBRARIES} pthread rt)
endif()

You can see I have to add some versions of Boost because my version of CMake doesn't know last versions. What's your CMake version ? Maybe it's the same problem.

0
votes

Where are your headers? I don't think it found the include directory (which is necessary for this to be successful).

Search for FindBoost.cmake in your cmake installation directory, there are lots of useful things in there for troubleshooting.

using set(Boost_DEBUG ON) can help you figure out which paths are searched and what the filenames of the libraries are searched. You can specify the include directory (directory where folder boost is stored) with set(Boost_INCLUDEDIRS ${BOOST_ROOT}/inc), though what I just showed is one of the places that FindBoost.cmake searches.

Also, you don't need set(BOOST_ROOT "$ENV{BOOST_ROOT}"). FindBoost.cmake does that for you if you don't set ${BOOST_ROOT}.

Note that if you just downloaded boost, extracted the archive to ${BOOST_ROOT} and compiled with b2, then all of your files are in ${BOOST_ROOT}/stage. This is also a good place for them to reside. If you manually copy files somewhere else, then FindBoost may have some troubles finding them.