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.
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)