3

I have downloaded and build Boost as described in the Getting Started on Windows Documentation. Now i want to link a sample program to that Version of Boost via CMake.

This is my current Folder Structure:

cmake-boost
    - boost_1_73_0/ (Boost folder)
    - build/
    - CMakeLists.txt
    - cmake-boost.cpp

This is the content of my CMakeLists.txt File:

cmake_minimum_required(VERSION 3.5 FATAL_ERROR)

project(cmake-boost LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(BOOST_ROOT "boost_1_73_0")
set(BOOST_LIBRARYDIR "boost_1_73_0/stage/lib")

find_package(Boost REQUIRED COMPONENTS regex)

if(Boost_FOUND)
    message(STATUS "Success!")
endif()

add_executable(cmake-boost cmake-boost.cpp)

target_link_libraries(cmake-boost
    PUBLIC
        Boost::regex
)

If i run cmake .. from inside the build Folder all i get is the following Message saying it could not find the requested Library.

CMake Warning at C:/Program Files/CMake/share/cmake-3.14/Modules/FindBoost.cmake:896 (message):
  New Boost version may have incorrect or missing dependencies and imported
  targets
Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.14/Modules/FindBoost.cmake:1018 (_Boost_COMPONENT_DEPENDENCIES)
  C:/Program Files/CMake/share/cmake-3.14/Modules/FindBoost.cmake:1694 (_Boost_MISSING_DEPENDENCIES)
  CMakeLists.txt:12 (find_package)


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

  Boost version: 1.73.0

  Boost include path:
  C:/Users/djc3ho/Documents/Programming/cpp/_Testing/cmake_boost/boost_1_73_0


  Could not find the following Boost libraries:

          boost_regex

  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:12 (find_package)


-- Configuring incomplete, errors occurred!

What is wrong with my CMakeFile?

UPDATE:

Here is the output of cmake -DBoost_DEBUG=ON ..

-- Building for: Visual Studio 16 2019
-- Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.17763.
-- The CXX compiler identification is MSVC 19.26.28806.0
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.26.28801/bin/Hostx64/x64/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.26.28801/bin/Hostx64/x64/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- [ C:/Program Files/CMake/share/cmake-3.14/Modules/FindBoost.cmake:1181 ] _boost_TEST_VERSIONS = 1.70.0;1.70;1.69.0;1.69
-- [ C:/Program Files/CMake/share/cmake-3.14/Modules/FindBoost.cmake:1183 ] Boost_USE_MULTITHREADED = TRUE
-- [ C:/Program Files/CMake/share/cmake-3.14/Modules/FindBoost.cmake:1185 ] Boost_USE_STATIC_LIBS =
-- [ C:/Program Files/CMake/share/cmake-3.14/Modules/FindBoost.cmake:1187 ] Boost_USE_STATIC_RUNTIME =
-- [ C:/Program Files/CMake/share/cmake-3.14/Modules/FindBoost.cmake:1189 ] Boost_ADDITIONAL_VERSIONS =
-- [ C:/Program Files/CMake/share/cmake-3.14/Modules/FindBoost.cmake:1191 ] Boost_NO_SYSTEM_PATHS =
-- [ C:/Program Files/CMake/share/cmake-3.14/Modules/FindBoost.cmake:1259 ] Declared as CMake or Environmental Variables:
-- [ C:/Program Files/CMake/share/cmake-3.14/Modules/FindBoost.cmake:1261 ]   BOOST_ROOT = boost_1_73_0
-- [ C:/Program Files/CMake/share/cmake-3.14/Modules/FindBoost.cmake:1263 ]   BOOST_INCLUDEDIR =
-- [ C:/Program Files/CMake/share/cmake-3.14/Modules/FindBoost.cmake:1265 ]   BOOST_LIBRARYDIR = boost_1_73_0/stage/lib
-- [ C:/Program Files/CMake/share/cmake-3.14/Modules/FindBoost.cmake:1267 ] _boost_TEST_VERSIONS = 1.70.0;1.70;1.69.0;1.69
-- [ C:/Program Files/CMake/share/cmake-3.14/Modules/FindBoost.cmake:1342 ] Include debugging info:
-- [ C:/Program Files/CMake/share/cmake-3.14/Modules/FindBoost.cmake:1344 ]   _boost_INCLUDE_SEARCH_DIRS = boost_1_73_0/include;boost_1_73_0;PATHS;C:/local/boost_1_70_0;PATHS;C:/local/boost_1_70;PATHS;C:/local/boost_1_69_0;PATHS;C:/local/boost_1_69;PATHS;C:/boost/include;C:/boost;/sw/local/include
-- [ C:/Program Files/CMake/share/cmake-3.14/Modules/FindBoost.cmake:1346 ]   _boost_PATH_SUFFIXES = boost-1_70_0;boost_1_70_0;boost/boost-1_70_0;boost/boost_1_70_0;boost-1_70;boost_1_70;boost/boost-1_70;boost/boost_1_70;boost-1_69_0;boost_1_69_0;boost/boost-1_69_0;boost/boost_1_69_0;boost-1_69;boost_1_69;boost/boost-1_69;boost/boost_1_69
-- [ C:/Program Files/CMake/share/cmake-3.14/Modules/FindBoost.cmake:1366 ] location of version.hpp: C:/Users/djc3ho/Documents/Programming/cpp/_Testing/cmake_boost/boost_1_73_0/boost/version.hpp
-- [ C:/Program Files/CMake/share/cmake-3.14/Modules/FindBoost.cmake:1391 ] version.hpp reveals boost 1.73.0
-- [ C:/Program Files/CMake/share/cmake-3.14/Modules/FindBoost.cmake:1447 ] Boost_LIB_PREFIX =
-- [ C:/Program Files/CMake/share/cmake-3.14/Modules/FindBoost.cmake:1449 ] Boost_NAMESPACE = boost
-- [ C:/Program Files/CMake/share/cmake-3.14/Modules/FindBoost.cmake:1484 ] guessed _boost_COMPILER = -vc141;-vc140
-- [ C:/Program Files/CMake/share/cmake-3.14/Modules/FindBoost.cmake:1494 ] _boost_MULTITHREADED = -mt
-- [ C:/Program Files/CMake/share/cmake-3.14/Modules/FindBoost.cmake:1578 ] _boost_RELEASE_ABI_TAG = -
-- [ C:/Program Files/CMake/share/cmake-3.14/Modules/FindBoost.cmake:1580 ] _boost_DEBUG_ABI_TAG = -gd
-- [ C:/Program Files/CMake/share/cmake-3.14/Modules/FindBoost.cmake:1643 ] _boost_LIBRARY_SEARCH_DIRS_RELEASE = boost_1_73_0/stage/lib;boost_1_73_0/lib;boost_1_73_0/stage/lib;boost_1_73_0/lib64-msvc-14.1;boost_1_73_0/lib64-msvc-14.0;C:/Users/djc3ho/Documents/Programming/cpp/_Testing/cmake_boost/boost_1_73_0/lib;C:/Users/djc3ho/Documents/Programming/cpp/_Testing/cmake_boost/boost_1_73_0/../lib;C:/Users/djc3ho/Documents/Programming/cpp/_Testing/cmake_boost/boost_1_73_0/stage/lib;C:/Users/djc3ho/Documents/Programming/cpp/_Testing/cmake_boost/boost_1_73_0/../lib64-msvc-14.1;C:/Users/djc3ho/Documents/Programming/cpp/_Testing/cmake_boost/boost_1_73_0/../lib64-msvc-14.0;C:/Users/djc3ho/Documents/Programming/cpp/_Testing/cmake_boost/boost_1_73_0/lib64-msvc-14.1;C:/Users/djc3ho/Documents/Programming/cpp/_Testing/cmake_boost/boost_1_73_0/lib64-msvc-14.0;C:/local/boost_1_70_0/lib64-msvc-14.1;C:/local/boost_1_70_0/lib64-msvc-14.0;C:/local/boost_1_70/lib64-msvc-14.1;C:/local/boost_1_70/lib64-msvc-14.0;C:/local/boost_1_69_0/lib64-msvc-14.1;C:/local/boost_1_69_0/lib64-msvc-14.0;C:/local/boost_1_69/lib64-msvc-14.1;C:/local/boost_1_69/lib64-msvc-14.0;C:/boost/lib64-msvc-14.1;C:/boost/lib64-msvc-14.0;PATHS;C:/boost/lib;C:/boost;/sw/local/lib_boost_LIBRARY_SEARCH_DIRS_DEBUG   = boost_1_73_0/stage/lib;boost_1_73_0/lib;boost_1_73_0/stage/lib;boost_1_73_0/lib64-msvc-14.1;boost_1_73_0/lib64-msvc-14.0;C:/Users/djc3ho/Documents/Programming/cpp/_Testing/cmake_boost/boost_1_73_0/lib;C:/Users/djc3ho/Documents/Programming/cpp/_Testing/cmake_boost/boost_1_73_0/../lib;C:/Users/djc3ho/Documents/Programming/cpp/_Testing/cmake_boost/boost_1_73_0/stage/lib;C:/Users/djc3ho/Documents/Programming/cpp/_Testing/cmake_boost/boost_1_73_0/../lib64-msvc-14.1;C:/Users/djc3ho/Documents/Programming/cpp/_Testing/cmake_boost/boost_1_73_0/../lib64-msvc-14.0;C:/Users/djc3ho/Documents/Programming/cpp/_Testing/cmake_boost/boost_1_73_0/lib64-msvc-14.1;C:/Users/djc3ho/Documents/Programming/cpp/_Testing/cmake_boost/boost_1_73_0/lib64-msvc-14.0;C:/local/boost_1_70_0/lib64-msvc-14.1;C:/local/boost_1_70_0/lib64-msvc-14.0;C:/local/boost_1_70/lib64-msvc-14.1;C:/local/boost_1_70/lib64-msvc-14.0;C:/local/boost_1_69_0/lib64-msvc-14.1;C:/local/boost_1_69_0/lib64-msvc-14.0;C:/local/boost_1_69/lib64-msvc-14.1;C:/local/boost_1_69/lib64-msvc-14.0;C:/boost/lib64-msvc-14.1;C:/boost/lib64-msvc-14.0;PATHS;C:/boost/lib;C:/boost;/sw/local/lib
CMake Warning at C:/Program Files/CMake/share/cmake-3.14/Modules/FindBoost.cmake:896 (message):
  New Boost version may have incorrect or missing dependencies and imported
  targets
Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.14/Modules/FindBoost.cmake:1018 (_Boost_COMPONENT_DEPENDENCIES)
  C:/Program Files/CMake/share/cmake-3.14/Modules/FindBoost.cmake:1694 (_Boost_MISSING_DEPENDENCIES)
  CMakeLists.txt:12 (find_package)


-- [ C:/Program Files/CMake/share/cmake-3.14/Modules/FindBoost.cmake:1833 ] Searching for REGEX_LIBRARY_RELEASE: boost_regex-vc141-mt-x64-1_73;boost_regex-vc141-mt;boost_regex-vc140-mt-x64-1_73;boost_regex-vc140-mt;boost_regex-mt-x64-1_73;boost_regex-mt;boost_regex-mt;boost_regex
-- [ C:/Program Files/CMake/share/cmake-3.14/Modules/FindBoost.cmake:1886 ] Searching for REGEX_LIBRARY_DEBUG: boost_regex-vc141-mt-gd-x64-1_73;boost_regex-vc141-mt-gd;boost_regex-vc140-mt-gd-x64-1_73;boost_regex-vc140-mt-gd;boost_regex-mt-gd-x64-1_73;boost_regex-mt-gd;boost_regex-mt;boost_regex
-- [ C:/Program Files/CMake/share/cmake-3.14/Modules/FindBoost.cmake:1960 ] Boost_FOUND = 1
CMake Error at C:/Program Files/CMake/share/cmake-3.14/Modules/FindBoost.cmake:2124 (message):
  Unable to find the requested Boost libraries.

  Boost version: 1.73.0

  Boost include path:
  C:/Users/djc3ho/Documents/Programming/cpp/_Testing/cmake_boost/boost_1_73_0


  Could not find the following Boost libraries:

          boost_regex

  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:12 (find_package)

I have noticed two things which are possible wrong:

  1. This line -- [ C:/Program Files/CMake/share/cmake-3.14/Modules/FindBoost.cmake:1484 ] guessed _boost_COMPILER = -vc141;-vc140 but if i look at the .lib Files generated during the build of boost, they have the -vc142 in their name
  2. It seems that cmake searching the right folder but with the wrong name of the library file. It uses the name boost_regex-vc141-mt-x64-1_73 but the lib files from my boost build startet with lib like libboost_regex-vc142-mt-x64-1_73.lib

I solved the first issue by adding -DBoost_COMPILER=-v142 to the cmake command. But i could not set the Boost_LIB_PREFIX with -DBoost_LIB_PREFIX=lib

Kevin
  • 785
  • 2
  • 10
  • 32
  • Does this answer your question? [How can I get CMake to find my alternative Boost installation?](https://stackoverflow.com/questions/3016448/how-can-i-get-cmake-to-find-my-alternative-boost-installation) – Marek R Jun 16 '20 at 09:15
  • @MarekR that's right, my bad – Proko Jun 16 '20 at 09:20
  • 1
    According to the path `C:/Users/djc3ho/Documents/Programming/cpp/_Testing/cmake_boost/boost_1_73_0` in the log, CMake has been able to find Boost in your location at least **partially**. The issue is that CMake cannot locate `boost_regex` library in your location. For debug this issue run `cmake` with additional option `-DBoost_DEBUG=ON`. With this option CMake will output exact files which are checked. Compare them with ones you actually have in your installation. Note also to warning `New Boost version may have incorrect ...` - it could signal about the core of your problem. – Tsyvarev Jun 16 '20 at 09:48
  • @MarekR i have used the mentioned question as a base for my problem but it does not solve it.I also tried it with full paths but it also did not work – Kevin Jun 16 '20 at 10:21
  • 1
    In CMake 3.14 `-vc141` and `-vc140` are the highest compiler suffixes known for [FindBoost.cmake](https://github.com/Kitware/CMake/blob/v3.14.0/Modules/FindBoost.cmake#L470). E.g. in CMake 3.17.3 [FindBoost.cmake](https://github.com/Kitware/CMake/blob/v3.17.3/Modules/FindBoost.cmake#L724) knows about the full range of suffixes, `-vc149`, `-vc148`, ... `-vc140`. So, the warning `New Boost version` is actually relevant to your problem: newer versions of CMake wouldn't require setting `Boost_COMPILER` variable. (This by no means intend to lower your investigations and the answer). – Tsyvarev Jun 16 '20 at 15:50
  • @Tsyvarev thank you for that explanation. Maybe I try to update my Version of Cmake. I was wondering why cmake just detects the vc141 and not the vc141. – Kevin Jun 16 '20 at 18:34

1 Answers1

3

I have found a solution. As mentioned in the last edit I made to my question, the first issue with the compiler could be fixed with the -DBoost_COMPILER=-vc142 option. The second could be solved by using the -DBoost_USE_STATIC_LIBS=ON.

So the set block in the CMakeLists for boost is now:

set(BOOST_ROOT "boost_1_73_0")
set(Boost_COMPILER "-vc142")
set(Boost_USE_STATIC_LIBS ON)

With these variables set, CMake runs without any problems.

Kevin
  • 16,549
  • 8
  • 60
  • 74
Kevin
  • 785
  • 2
  • 10
  • 32