Cmake Is Not Finding Boost

Cmake doesn't find Boost

Are you sure you are doing it the correct way? The idea is that CMake sets BOOST_INCLUDE_DIR, BOOST_LIBRARYDIR and BOOST_ROOT automatically. Do something like this in CMakeLists.txt:

FIND_PACKAGE(Boost)
IF (Boost_FOUND)
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIR})
ADD_DEFINITIONS( "-DHAS_BOOST" )
ENDIF()

If boost is not installed in a default location and can, thus, not be found by CMake, you can tell CMake where to look for boost like this:

SET(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "C:/win32libs/boost")
SET(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "C:/win32libs/boost/lib")

Of course, those two lines have to be before the FIND_PACKAGE(Boost) in CMakeLists.txt.

Cmake error: Could NOT find Boost (missing: Boost_INCLUDE_DIR)

I solved this by adding sentence set(BOOST_ROOT C:/local/boost_1_71_0) before find_package(Boost REQUIRED) LOL...
But I still wonder why I need to add this.

CMake does not find Boost on Custom Location on Windows

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.



Related Topics



Leave a reply



Submit