I am trying to add Boost to a C++ application using CMake. I have read through all relevant questions I can find on SO, and I feel I am getting closer to a solution. But the CMake still can't find the requested Boost library for some reasons.
I am trying to find "boost_filesystem". The debug shows CMake is looking for "boost_filesystem-vc141-mt-gd-1_65_1". I do have the file "libboost_filesystem-vc141-mt-gd-1_65_1.lib" in the folder "C:\boost\boost_1_65_1\stage\lib". I suppose this is the file CMake is looking for, but for some reasons CMake says it can't find it.
Here is the procedure I used to build the Boost. This may be too much details for most people but I suspect it may be helpful to another newbie.
- download and extract Boost 1.65.1 in folder C:\boost\boost_1_65_1
- go to developer prompt command line and run bootstrap.bat under the above folder.
- updated file visualc.hpp under C:\boost\boost_1_65_1\boost\config\compiler (see Unknown compiler version while compiling Boost with MSVC 14.0 (VS 2015)!
Replaced the lines in the bottom of the file visualc.hpp :
// last known and checked version is 19.11.25506 (VC++ 2017.3):
#if (_MSC_VER > 1911)
with
// last known and checked version is 19.13.26128 (VC++ 2017.5.6):
#if (_MSC_VER > 1913)
Open another file project-config.jam under the folder boost_1_65_1 and updated the second line to the following:
using msvc : 14.1 : "C:\Program Files (x86)\Microsoft Visual Studio\2017 \Professional\VC\Tools\MSVC\14.13.26128\bin\Hostx64\x64\cl.exe" ;
Go back to developer prompt command line and run the following to build Boost:
b2 toolset=msvc-14.1 address-model=64
It seems I have done the following items correctly:
- properly built the libraries, though not using the default directory. I confirmed that the requested library is built.
- assigned the path correctly to the CMake designated directories
- used CMake find_package() correctly
Here are the relevant versions I am using:
- VS: 2017 v15.6.1 with CMake 3.10
- Boost version: 1.65.1, built with tool MSVC 14.1
Here is the CMakelist.txt:
cmake_minimum_required(VERSION 3.6 FATAL_ERROR)
project(test)
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
set(Boost_DEBUG ON)
set(BOOST_ROOT C:\\boost\\boost_1_65_1)
set(BOOST_INCLUDEDIR C:\\boost\\boost_1_65_1)
set(BOOST_LIBRARYDIR C:\\boost\\boost_1_65_1\\stage\\lib)
set(Boost_DEBUG 1)
find_package(Boost COMPONENTS filesystem REQUIRED)
message(STATUS "Boost LIBRARIES: " ${Boost_LIBRARIES})
add_executable(test_Boost main.cpp)
target_link_libraries(test_Boost ${Boost_LIBRARIES})
here is part of the output that may be relevant:
1> Command line: C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2017\PROFESSIONAL\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe -G "Ninja" -DCMAKE_INSTALL_PREFIX:PATH="C:\Users\david\CMakeBuilds\94321a3b-9fa8-083f-a86f-e151c3abae79\install\x64-Release" -DCMAKE_CXX_COMPILER="C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/VC/Tools/MSVC/14.13.26128/bin/HostX64/x64/cl.exe" -DCMAKE_C_COMPILER="C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/VC/Tools/MSVC/14.13.26128/bin/HostX64/x64/cl.exe" -DCMAKE_BUILD_TYPE="RelWithDebInfo" -DCMAKE_MAKE_PROGRAM="C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2017\PROFESSIONAL\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" "E:\computer\boost\cmake"
1> Working directory: C:\Users\david\CMakeBuilds\94321a3b-9fa8-083f-a86f-e151c3abae79\build\x64-Release
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1073 ] _boost_TEST_VERSIONS = 1.65.1;1.65.0;1.65;1.64.0
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1075 ] Boost_USE_MULTITHREADED = ON
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1077 ] Boost_USE_STATIC_LIBS = OFF
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1079 ] Boost_USE_STATIC_RUNTIME = OFF
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1081 ] Boost_ADDITIONAL_VERSIONS =
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1083 ] Boost_NO_SYSTEM_PATHS =
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1151 ] Declared as CMake or Environmental Variables:
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1153 ] BOOST_ROOT = C:\boost\boost_1_65_1
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1155 ] BOOST_INCLUDEDIR = C:\boost\boost_1_65_1
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1157 ] BOOST_LIBRARYDIR = C:\boost\boost_1_65_1\stage\lib
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1159 ] _boost_TEST_VERSIONS = 1.65.1;1.65.0;1.65;1.64.0;...
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1258 ] location of version.hpp: C:/boost/boost_1_65_1/boost/version.hpp
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1282 ] version.hpp reveals boost 1.65.1;...
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1368 ] guessed _boost_COMPILER = -vc141;-vc140
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1378 ] _boost_MULTITHREADED = -mt
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1422 ] _boost_RELEASE_ABI_TAG = -
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1424 ] _boost_DEBUG_ABI_TAG = -gd
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1486 ] _boost_LIBRARY_SEARCH_DIRS_RELEASE = C:\boost\boost_1_65_1\stage\lib;C:\boost\boost_1_65_1/lib;...
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1636 ] Searching for FILESYSTEM_LIBRARY_RELEASE: boost_filesystem-vc141-mt-1_65_1;boost_filesystem-vc141-mt
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1687 ] Searching for FILESYSTEM_LIBRARY_DEBUG: boost_filesystem-vc141-mt-gd-1_65_1;boost_filesystem-vc141-mt-gd
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1636 ] Searching for SYSTEM_LIBRARY_RELEASE: boost_system-vc141-mt-1_65_1;boost_system-vc141-mt
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1687 ] Searching for SYSTEM_LIBRARY_DEBUG: boost_system-vc141-mt-gd-1_65_1;boost_system-vc141-mt-gd
1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1762 ] Boost_FOUND = 1
1> -- Boost LIBRARIES:
1> CMake Error at C:/Program Files (x86)/.../FindBoost.cmake:1923 (message):
1> Unable to find the requested Boost libraries.
1>
1> Boost version: 1.65.1
1>
1> Boost include path: C:/boost/boost_1_65_1
1>
1> Could not find the following Boost libraries:
1>
1> boost_filesystem
1>
1> Some (but not all) of the required Boost libraries were found. You may
1> need to install these additional Boost libraries. Alternatively, set
1> BOOST_LIBRARYDIR to the directory containing Boost libraries or BOOST_ROOT
1> to the location of Boost.
1> Call Stack (most recent call first):
1> CMakeLists.txt(17): (find_package)
1>
1>
1> -- Configuring incomplete, errors occurred!
1> See also "C:/Users/david/CMakeBuilds/94321a3b-9fa8-083f-a86f-e151c3abae79/build/x64-Release/CMakeFiles/CMakeOutput.log".
1> C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2017\PROFESSIONAL\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe -G "Ninja" -DCMAKE_INSTALL_PREFIX:PATH="C:\Users\david\CMakeBuilds\94321a3b-9fa8-083f-a86f-e151c3abae79\install\x64-Release" -DCMAKE_CXX_COMPILER="C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/VC/Tools/MSVC/14.13.26128/bin/HostX64/x64/cl.exe" -DCMAKE_C_COMPILER="C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/VC/Tools/MSVC/14.13.26128/bin/HostX64/x64/cl.exe" -DCMAKE_BUILD_TYPE="RelWithDebInfo" -DCMAKE_MAKE_PROGRAM="C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2017\PROFESSIONAL\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" "E:\computer\boost\cmake" returned with exit code: 1
CMake Error at C:/Program Files (x86)/.../FindBoost.cmake:1923 (message):
Unable to find the requested Boost libraries.
Boost version: 1.65.1
Boost include path: C:/boost/boost_1_65_1
Could not find the following Boost libraries:
boost_filesystem
Some (but not all) of the required Boost libraries were found. You may
need to install these additional Boost libraries. Alternatively, 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:17 (find_package)
Boost_DEBUG
variable, so you may see (in build log) which exact file, corresponded tofilesystem
Boost's component, is searched and where. BTW, your code setBoost_DEBUG
variable twice, first toON
and then to1
. – Tsyvarevlibboost_filesystem-vc141-mt-gd-1_65_1.lib
- This is a static library (it haslib
prefix), but you askfind_package(Boost)
to find shared libraries (set(Boost_USE_STATIC_LIBS OFF)
). – Tsyvarev