Reputation: 3164
I'm trying to build a project on Linux via CMake that depends on Boost. The project's CMakeLists.txt contains the following line:
find_package(Boost 1.46 REQUIRED COMPONENTS system thread filesystem)
For reproducibility reasons I have installed the required Boost headers via conda install libboost
so that they are located under
~/anaconda3/envs/.../include/boost
instead of /usr/local/include
. Not when I run cmake
, I receive an error along the lines of:
CMake Warning at /usr/share/cmake-3.7/Modules/FindBoost.cmake:761 (message):
Imported targets not available for Boost version
Call Stack (most recent call first):
/usr/share/cmake-3.7/Modules/FindBoost.cmake:865 (_Boost_COMPONENT_DEPENDENCIES)
/usr/share/cmake-3.7/Modules/FindBoost.cmake:1470 (_Boost_MISSING_DEPENDENCIES)
cmake/Dependencies.cmake:5 (find_package)
CMakeLists.txt:43 (include)
What can I do to make CMake find my Boost headers?
Upvotes: 7
Views: 4902
Reputation: 1246
This works for me:
cmake .. -DCMAKE_PREFIX_PATH=$CONDA_PREFIX
This works because CMake has a well defined search order that it follows when looking for library packages. CMAKE_PREFIX_PATH tells CMake to search in a user specified directory. $CONDA_PREFIX is an environment variable set by Anaconda when you activate your environment. These two tools were designed to work together in this way.
Upvotes: 5
Reputation: 1973
To give CMake a hint, where Boost is installed on your system, you have to set the BOOST_ROOT
variable accordingly. In your example, this seems to be
BOOST_ROOT=~/anaconda3/envs/.../
Note that you have to specify the parent directory of the lib
and include
folders. The file tree should look like the following:
BOOST_ROOT/
|-- include/
| |-- boost/
| | |-- *.hpp
| | `-- ...
| `-- ...
`-- lib/
|-- libboost_*.so
`-- ...
Another note: You are writing about headers only, but keep in mind that those three components you want to use are not header-only, but are actual libraries that your program has to be linked against.
Upvotes: 4