0

I know this is another question like "where is my boost???, but it is still not clear for me... I'm newbie at Boost and Cmake. I'm trying to build simple demo from Boost tutorial (serialization lib required) with Cmake using this script:

cmake_minimum_required(VERSION 2.8)
project(serialization)
add_executable(serializer main.cpp)

set(BOOST_ROOT "C:/Dev/Source/boost/boost_1_73_0")
set(BOOST_INCLUDEDIR "C:/Dev/Source/boost/boost_1_73_0")
set(BOOST_LIBRARYDIR "C:/Dev/Source/boost/boost_1_73_0/stage/lib")
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
    
set(Boost_DEBUG 1)

find_package(Boost 1.73.0 REQUIRED COMPONENTS serialization)

if(Boost_FOUND)
    include_directories(${Boost_INCLUDE_DIRS})
    target_link_libraries(serializer ${Boost_LIBRARIES})
endif()

Cmake output looks like:

[build] -- [ C:/Dev/Source/...cmake:1489 ] Boost_USE_STATIC_LIBS = "ON"
...
[build] -- [ C:/Dev/Source/...cmake:1524 ] BOOST_ROOT = "C:/Dev/Source/boost/boost_1_73_0"
[build] -- [ C:/Dev/Source/...cmake:1525 ] ENV{BOOST_ROOT} = <unset>
...
[build] -- [ C:/Dev/Source/...cmake:1526 ] BOOST_INCLUDEDIR = "C:/Dev/Source/boost/boost_1_73_0"
[build] -- [ C:/Dev/Source/...cmake:1526 ] ENV{BOOST_INCLUDEDIR} = <unset>
...
[build] -- [ C:/Dev/Source/...cmake:1528 ] BOOST_LIBRARYDIR = "C:/Dev/Source/boost/boost_1_73_0/stage/lib"
[build] -- [ C:/Dev/Source/...cmake:1529 ] ENV{BOOST_LIBRARYDIR} = <unset>
...
[build] -- [ C:/Dev/Source/...cmake:2045 ] Searching for SERIALIZATION_LIBRARY_RELEASE: libboost_serialization-mgw8-mt-1_73;...;libboost_serialization-mt-s
[build] -- [ C:/Dev/Source/...cmake:2100 ] Searching for SERIALIZATION_LIBRARY_DEBUG: libboost_serialization-mgw8-mt-d-1_73;...;libboost_serialization-mt-s-d
...
[build] CMake Error at C:/Dev/Source/...cmake:164 (message):
[build]   Could NOT find Boost (missing: serialization) (found suitable version
[build]   "1.73.0", minimum required is "1.73.0")

so it seems like Cmake can find required libraries but something goes wrong. And if I don't specify COMPONENTS explicitly, Cmake finds Boost but build process fails with many undefined reference to boost::... errors. So is there a way to fix these problems?

  • Welcome to Stack Overflow! Please look at the `Boost_DEBUG` output as it is there to assist you. Specifically, do the searched libraries (e.g. `libboost_serialization-mgw8-mt-1_73;...`) match the *names* of the Boost libraries that actually exist on your machine? If not, you likely have a **mismatch** between the compiler/architecture you're using with CMake and the compiler/architecture used to *build* the Boost libraries. Additionally, MinGW may require you to set `Boost_ARCHITECTURE`, as described [here](https://stackoverflow.com/a/53982096/3987854). – Kevin Aug 11 '20 at 11:32
  • Many thanks! It was really useful advice. I couldn't even think that here can be such a problem as different compilers for Cmake and Boost... – Dmitry Kochetov Aug 11 '20 at 12:13
  • Surely. So, do the searched libraries match the names of the Boost libraries that actually exist on your machine? – Kevin Aug 11 '20 at 12:32
  • No, so I had to set Boost_COMPILER and Boost_ARCHITECTURE. Then it worked. But here comes new trouble with linking libraries... but that's another story – Dmitry Kochetov Aug 12 '20 at 11:59
  • Yes, that indicates there may be a *mismatch* between the compiler used with CMake, and the compiler used to build the Boost libraries, as I earlier commented. Thus, adding `Boost_COMPILER` and similar variables may help CMake find the Boost libraries, but the *mismatch still exists*, and linking will most likely fail. You need to build the Boost libraries using the **same** compiler and architecture you intend to use in the your CMake project. – Kevin Aug 12 '20 at 13:03

0 Answers0