I need to build a C++ program with CMake but it cannot find Boost.
I’m getting the following error no matter what solutions I’ve found online for other people with this problem…
-- Compiling with C++ standard: 17
CMake Error at /usr/share/cmake-3.22/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
Could NOT find Boost (missing: Boost_INCLUDE_DIR) (Required is at least
version "1.68.0")
Call Stack (most recent call first):
/usr/share/cmake-3.22/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake-3.22/Modules/FindBoost.cmake:2360 (find_package_handle_standard_args)
CMakeLists.txt:49 (find_package)
This is the part of my CMakeLists.txt looking for Boost
if(NUMCPP_NO_USE_BOOST)
target_compile_definitions(${ALL_INTERFACE_TARGET} INTERFACE -DNUMCPP_NO_USE_BOOST)
else()
find_package(Boost 1.68.0 REQUIRED)
target_link_libraries(${ALL_INTERFACE_TARGET} INTERFACE Boost::boost)
endif()
I have installed boost with sudo apt-get install libboost-all-dev
and a few other apt-get options. I always see 0 upgraded, 0 newly installed, 0 to remove
after running.
$ whereis boost
boost: /usr/include/boost
Do I need to specify it in the cmake .. line in the terminal somehow?
2
Answers
Assuming that you’ve successfully installed boost in the default directory, and CMake has access to those directories, probably the problem (as @drescherjm mentioned) is in the version of the Boost you’ve installed (sometimes the packages provided by
apt-get
are relatively old).On the other hand it can also be that CMake doesn’t have the installation directory in its search path.
The following steps might be a good place to start:
If the version installed by
apt-get
satisfies the project requirement, it seems for some reason CMake didn’t include a directory of installation to its searching path. If that’s the case, skip to the step 3.I hope this reply is not too off-topic. I suggest you consider using a package manager such as conan or vcpkg.
An example of using
conan
to use external dependencies.1. Create
conanfile.txt
It should have the following content:
2. Download your dependencies
The last command is optional and can be changed with:
Benefits: