0

I begin by saying that this is not an issue with environment variables.

When I use the header-only libraries, everything works fine with this:

set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost REQUIRED)

if(Boost_FOUND)
    include_directories(${Boost_INCLUDE_DIRS})
    add_executable(TestCMake Program.cpp)
    target_link_libraries(TestCMake ${Boost_LIBRARIES})
endif()

But when I try to require a library by changing find_package(Boost REQUIRED) to find_package(Boost REQUIRED COMPONENTS system) I get an error:

Unable to find the requested Boost libraries.

Boost version: 1.67.0

Boost include path: D:/boost/boost_1_67_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.

This answer on another question suggests that CMake expects the Boost binaries to be named in a certain way:

boost_thread-vc100-mt-1_51
boost_thread-vc100-mt
boost_thread-mt-1_51
boost_thread-mt
boost_thread

I have a precompiled binary (acquired from here) named boost_system-vc141-mt-x32-1_67.lib. How could I make CMake recognize the naming convention used in my binaries?

Comments for this downvoted answer on that other question suggest against renaming the files.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
user3670011
  • 194
  • 11
  • 2
    Which CMake version are you using? Only after 3.11 does CMake support the new Boost naming convention. You can also use a more recent FindBoost in your project, that works as well. No need to rename anything. – Matthieu Brucher Nov 24 '18 at 10:08
  • Oh wow, I'm actually using 3.10. I feel so stupid now for wasting over 2 hours on this already. – user3670011 Nov 24 '18 at 10:18

1 Answers1

2

In newer versions of Boost (1.66 and forward), the naming convention of the binaries has changed. Now, there is an additional x64 or x32.

As such, only CMake versions posterior to the 1.66 Boost release have this fix, which is the case starting at 3.11.

So two options for you:

  • Upgrade your CMake version to something above 3.11
  • Use the FindBoost.cmake from one of these newer CMake versions (they usually are compatible).

The latter solution would have to be used if you are "stuck" with one version due to company policies.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Matthieu Brucher
  • 21,634
  • 7
  • 38
  • 62
  • It doesn't work in 3.12. `[ C:/Program Files/CMake/share/cmake-3.12/Modules/FindBoost.cmake:1809 ] Searching for SYSTEM_LIBRARY_DEBUG: libboost_system-mgw73-mt-d-1_68;libboost_system-mgw73-mt-d;libboost_system-mt-d-1_68;libboost_system-mt-d;libboost_system-mt;libboost_system;libboost_system-mgw73-mt-s-d-1_68;libboost_system-mgw73-mt-s-d;libboost_system-mt-s-d-1_68;libboost_system-mt-s-d` – Mariusz Jaskółka Feb 21 '19 at 14:36