I'm trying to configure a project using CMake, but it fails to find Boost libraries even though they are in the specified folder. I have specified Boost_INCLUDE_DIR
, Boost_LIBRARYDIR
and BOOST_ROOT
, but I still get an error saying that CMake is not able to find Boost. What could be the reason of such error?
You can use find_package to search for available boost libraries. It defers searching for Boost to FindBoost. cmake, which is default installed with CMake. Upon finding Boost, the find_package() call will have filled many variables (check the reference for FindBoost.
You can check version. hpp inside Boost include dir (normally /usr/include/boost , you can use locate /boost/version. hpp or similar to get that) for BOOST_VERSION or BOOST_LIB_VERSION .
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
.
There is more help available by reading the FindBoost.cmake
file itself. It is located in your 'Modules' directory.
A good start is to set(Boost_DEBUG 1)
- this will spit out a good deal of information about where boost is looking, what it's looking for, and may help explain why it can't find it.
It can also help you to figure out if it is picking up on your BOOST_ROOT
properly.
FindBoost.cmake
also sometimes has problems if the exact version of boost is not listed in the Available Versions variables. You can find more about this by reading FindBoost.cmake
.
Lastly, FindBoost.cmake
has had some bugs in the past. One thing you might try is to take a newer version of FindBoost.cmake
out of the latest version of CMake, and stick it into your project folder alongside CMakeLists.txt
- then even if you have an old version of boost, it will use the new version of FindBoost.cmake
that is in your project's folder.
Good luck.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With