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
.
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.
I struggled with this problem for a while myself. It turned out that cmake
was looking for Boost library files using Boost's naming convention, in which the library name is a function of the compiler version used to build it. Our Boost libraries were built using GCC 4.9.1
, and that compiler version was in fact present on our system; however, GCC 4.4.7
also happened to be installed. As it happens, cmake's FindBoost.cmake
script was auto-detecting the GCC 4.4.7
installation instead of the GCC 4.9.1
one, and thus was looking for Boost library files with "gcc44
" in the file names, rather than "gcc49
".
The simple fix was to force cmake to assume that GCC 4.9 was present, by setting Boost_COMPILER
to "-gcc49
" in CMakeLists.txt
. With this change, FindBoost.cmake
looked for, and found, my Boost library files.