Hi all,
I have seen various posts across the Internet about getting CMake to work with Boost 1.70+ and it seems like everyone has an easier time than I am. I think I must be doing something wrong.
So, I am using CMake 3.30.3 and Boost 1.85.0 under Ubuntu 24.10. Boost is compiled from source and not installed as Ubuntu packages. BOOST_ROOT has the value of /usr/local/boost
, which is a symbolic link to /usr/local/boost_1_85_0/
.
Removing various things I have tried, this is a minimum example, up to where I am stuck at:
if (POLICY CMP0167)
cmake_policy (SET CMP0167 NEW)
endif ()
set (Boost_VERBOSE ON)
set (Boost_DEBUG ON)
set (BOOST_MIN_VERSION 1.85.0)
set (BOOST_REQUIRED_COMPONENTS program_options)
find_package (Boost ${BOOST_MIN_VERSION} REQUIRED COMPONENTS ${BOOST_COMPILED_LIBRARIES})
If I change the policy to OLD
, then there aren’t any problems. When it is set to NEW
, I get the following error:
CMake Error at cmake/boost.cmake:66 (find_package):
By not providing “FindBoost.cmake” in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by “Boost”, but
CMake did not find one.Could not find a package configuration file provided by “Boost” (requested
version 1.85.0) with any of the following names:BoostConfig.cmake boost-config.cmake
Add the installation prefix of “Boost” to CMAKE_PREFIX_PATH or set
“Boost_DIR” to a directory containing one of the above files. If “Boost”
provides a separate development package or SDK, be sure it has been
installed.
My system doesn’t have a boost-config.cmake
. But BoostConfig.cmake
are in these locations:
$ locate BoostConfig.cmake
/usr/local/boost_1_85_0/tools/boost_install/BoostConfig.cmake
/usr/local/boost_1_85_0/tools/cmake/config/BoostConfig.cmake
I thought I should try setting Boost_DIR
to what the error message is suggesting to me. So, if add set (Boost_DIR "/usr/local/boost_1_85_0/tools/cmake/config/")
, then the error message becomes:
CMake Error at cmake/boost.cmake:66 (find_package):
Could not find a configuration file for package “Boost” that is compatible
with requested version “1.85.0”.The following configuration files were considered but not accepted:
/usr/local/boost_1_85_0/tools/cmake/config/BoostConfig.cmake, version: unknown
I feel like I’m doing something wrong because:
- Others having similar problems to me don’t seem to set
Boost_DIR
. Instead, settingBOOST_ROOT
as an shell environment variable was sufficient. - Under the old way, I only had to set
BOOST_ROOT
and I thought the old way and the new way were interchangeable – i.e., without many changes to code.
The last error I received seems to indicate that it isn’t happy with the BoostConfig.cmake
. I thought maybe there’s a problem with that file, but if there was, then others would have this problem. I also tried version 1.87.0 before this and it gave me the same problem. So, I’m fairly convinced it is my problem…
It is possible I installed Boost incorrectly, but if that were the case, then the OLD policy wouldn’t work.
Any suggestions would be appreciated! Thank you!
Ray