I installed boost from the source file in CentOS7
, I do these steps :
I checked and all file was correctly in /opt/boost/lib
then I want to compile my project but CMake couldn't find the correct version of boost :
I compile it whit this command :
cmake -DBOOST_INCLUDEDIR=/opt/boost/lib/ -DCMAKE_BUILD_TYPE=Debug .. -G "Unix Makefiles"
I got this Error :
CMake Error at /usr/local/share/cmake-3.12/Modules/FindBoost.cmake:2048 (message):
Unable to find the requested Boost libraries.Boost version: 1.53.0
Boost include path: /usr/include
Detected version of Boost is too old. Requested version was 1.67 (or newer). Call Stack (most recent call first): CMakeLists.txt:13 (FIND_PACKAGE)
what should I do?
You should not try and specify the include and library directories directly, instead, give the root directory (sometimes called installation prefix) as a hint to the find call.
You currently do -DBOOST_INCLUDEDIR=/opt/boost/lib/
, but /opt/boost/lib
does not actually contain any header files, so it's not a valid include directory, but rather the library directory. While it is possible to specify both library and include directories explicitly, doing so is fiddly and error-prone and therefore not recommended.
Instead you should provide the root directory for the library. When installing the library you will eventually end up with a directory structure like this:
/opt
+ boost
+ include
+ <all header files in here>
+ lib
+ <all library (.a and .so) files in here>
The root directory is the directory that contains both the include and library directories, so in this case it would be /opt/boost
.
In CMake versions 3.12 and higher, find_package
considers the <PackageName>_ROOT
CMake variable and the <PackageName>_ROOT
system environment variable as search hints. Additionally, the Boost find script that ships with CMake supports the BOOST_ROOT
and BOOSTROOT
CMake variables as search hints since pretty much forever.
So your command line really should look like this:
cmake -DBOOST_ROOT=/opt/boost -DCMAKE_BUILD_TYPE=Debug .. -G "Unix Makefiles"
If that still doesn't work, it most probably means that you're dealing with a non-standard directory layout. Consult the documentation for the FindBoost
script to figure out how to pass additional hints for such a situation, but really, I would strongly recommend to switch the directory layout instead.