0

I compiled boost library 1.78.0 for visual studio community edition 2019 (vc142). The library compiled fine and I got this message. The Boost C++ Libraries were successfully built!

The following directory should be added to compiler include paths:

C:\local\boost_1_78_0

The following directory should be added to linker library paths:

C:\local\boost_1_78_0\stage\lib

I created the environment variables to point to these BOOST_ROOT, BOOST_INCLUDEDIR to the root and BOOST_LIBRARYDIR to C:\local\boost_1_78_0\stage\lib.

In my top level CMakeLists.txt I tried to load the package.

if (POLICY CMP0074)
  cmake_policy(SET CMP0074 NEW)
endif()
find_package("Boost" 1.78.0 REQUIRED COMPONENTS system chrono unit_test_framework)
include_directories(${Boost_INCLUDE_DIRS})
link_directories(${Boost_LIBRARY_DIR})

But I am getting this error in visual studio

Severity    Code    Description Project File    Line    Suppression State Error
CMake Error at C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.20/Modules/FindPackageHandleStandardArgs.cmake:230 (message):   Could NOT find Boost (missing: system chrono unit_test_framework) (found   suitable version "1.78.0", minimum required is "1.78.0")       C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.20/Modules/FindPackageHandleStandardArgs.cmake   230

I do see that the library exists in the boost folder. Lib Folder View

Using the comment below I added the following flag to CMakeLists.txt

set(Boost_DEBUG ON)

With this I found that following variable was not set. Since I had static libs I needed cmake to looks for lib prefix. Following flag solved the issue.

set (Boost_USE_STATIC_LIBS ON)

I needed to make another tweak to load the chrono library by referrring to it as Boost::chrono instead of boost_chrono on linux.

add_executable(timer4 timer4.cpp)
target_link_libraries(timer4 Threads::Threads Boost::chrono)
Sanjeev Singh
  • 141
  • 1
  • 10
  • 1
    Potentially related: [CMake cannot find Boost libarary](https://stackoverflow.com/q/34669060/11082165) – Brian61354270 Jan 17 '22 at 03:45
  • 1
    There are several similar questions so how your differs? – Öö Tiib Jan 17 '22 at 04:01
  • When configure the project, pass additional `-DBoost_DEBUG=ON` option, or add the line `set(Boost_DEBUG ON)` before `find_package` call. That way CMake will show which exact Boost files are searched and where. – Tsyvarev Jan 17 '22 at 06:50
  • Thanks I forgot about this. With the debug message i found the issue. The variable Boost_USE_STATIC_LIBS was not set. In windows the static libs have "lib" prefix while the dll don't. So it was not using the correct prefix. Doing below solved the issue. set(Boost_USE_STATIC_LIBS ON) – Sanjeev Singh Jan 17 '22 at 15:53

0 Answers0