Boost+CMake: no suitable build variant - c++

I am trying to deploy some libraries on embedded SPARC-like machine for project in which I involved. I successfully built bleeding-edge Boost library on this machine and installed it into /util directory. Then I tried to write simple tester script for CMake. Here is the beginning of this script:
cmake_minimum_required(VERSION 2.8.3)
project(cpp_boost_test)
find_package(Boost REQUIRED COMPONENTS system thread)
find_package(console_bridge REQUIRED)
message(STATUS "Boost Includes: ${Boost_INCLUDE_DIRS}")
message(STATUS "Boost Libraries: ${Boost_LIBRARIES}")
While running I receive the following error message:
-- Found Boost 1.70.0 at /util/lib/cmake/Boost-1.70.0
-- Requested configuration: QUIET REQUIRED COMPONENTS
system;thread
-- Found boost_headers 1.70.0 at /util/lib/cmake/boost_headers-1.70.0
-- Found boost_system 1.70.0 at /util/lib/cmake/boost_system-1.70.0
-- No suitable boost_system variant has been identified!
-- libboost_system.so.1.70.0 (shared, BUILD_SHARED_LIBS not ON, set Boost_USE_STATIC_LIBS=OFF to override)
CMake Error at /util/lib/cmake/Boost-1.70.0/BoostConfig.cmake:60 (find_package):
Found package configuration file:
/util/lib/cmake/boost_system-1.70.0/boost_system-config.cmake
but it set boost_system_FOUND to FALSE so package "boost_system" is considered to be NOT FOUND.
Reason given by package:
No suitable build variant has been found.
Call Stack (most recent call first):
/util/lib/cmake/Boost-1.70.0/BoostConfig.cmake:89 (boost_find_dependency)
/util/share/cmake-3.7/Modules/FindBoost.cmake:229 (find_package)
CMakeLists.txt:4 (find_package)
I tried to set Boost_USE_STATIC_LIBS option but the error still remains.
Can this be a version conflict in Boost.System or not? What should I do to avoid this error? It is not possible to remove Boost from project, so I can not accept an answer about such removal...

I investigated the history of changes in Boost, so the answer is that building dependencies in projects linking Boost should be manually included into CMake (see answers here: CMake finds Boost but the imported targets not available for Boost version for details). Thus it is mandatory to use Boost version that is slightly older than CMake version you use. I solved my problem with rollback to Boost 1.61 (according to peculiarities of my embedded platform I can not compile CMake version above 3.7.0).

Check the version of your current cmake installation by using cmake --version.
It's highly likely greater than 3.0. Since there is an incompatibility between old cmake and modern cmake (>3.0), you can try to fix it by change the VERSION to your current cmake's version or any number >= 3.0.

Related

CMake - Unable to find boost components

I try to start a project with mlpack in C++ on macOS 12.0.1 with an Intel-CPU.
For development I use CLion, gcc/g++ 11.2.0 (installed via Homebrew), Clion's bundled cmake 3.20.2 and mlpack 3.4.2 (also installed via Homebrew).
Building the project fails due to the following error:
CMake Error at /usr/local/lib/cmake/Boost-1.76.0/BoostConfig.cmake:141 (find_package):
Could not find a package configuration file provided by
"boost_program_options," (requested version 1.76.0) with any of the
following names:
boost_program_options,Config.cmake
boost_program_options,-config.cmake
Add the installation prefix of "boost_program_options," to
CMAKE_PREFIX_PATH or set "boost_program_options,_DIR" to a directory
containing one of the above files. If "boost_program_options," provides a
separate development package or SDK, be sure it has been installed.
Call Stack (most recent call first):
/usr/local/lib/cmake/Boost-1.76.0/BoostConfig.cmake:258 (boost_find_component)
/Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.20/Modules/FindBoost.cmake:594 (find_package)
CMakeLists.txt:19 (find_package)
This error occurs even though I followed the instructions and defined the paths to boost_*_config.cmake. Here's the CMakeLists.txt:
cmake_minimum_required(VERSION 3.20)
project(cpp)
set(CMAKE_CXX_STANDARD 14)
include_directories(.)
include_directories(/usr/local/opt/armadillo/include)
include_directories(/usr/local/Cellar/mlpack/3.4.2_3/include/stb)
include_directories(/usr/local/opt/ensmallen/include)
include_directories(/usr/local/include)
include_directories(/usr/local/Cellar/mlpack/3.4.2_3/include/)
set(boost_program_options_DIR /usr/local/Cellar/boost/1.76.0/lib/cmake/boost_program_options-1.76.0/)
set(boost_math_c99_DIR /usr/local/Cellar/boost/1.76.0/lib/cmake/boost_math_c99-1.76.0)
set(boost_unit_test_framework_DIR /usr/local/Cellar/boost/1.76.0/lib/cmake/boost_unit_test_framework-1.76.0)
set(boost_serialization_DIR /usr/local/Cellar/boost/1.76.0/lib/cmake/boost_serialization-1.76.0)
set(boost_spirit_DIR /usr/local/Cellar/boost/1.76.0/lib/cmake/boost_spirit-1.76.0)
find_package(Boost 1.76.0 REQUIRED COMPONENTS program_options, math_c99, unit_test_framework, serialization, spirit)
message("${Boost_INCLUDE_DIRS}")
message("${Boost_LIBRARIES}")
include_directories(${Boost_INCLUDE_DIRS})
add_executable(cpp
cifar_train.cpp
cifar_eval.cpp)
target_link_libraries(cpp ${Boost_LIBRARIES})
The C++ code is just one of the mlpack examples, which can be found in their Github repository.
Since I'm relatively new to both CMake and C++ I can only guess what's wrong. To me it looks like something is not linked properly.

Problems linking boost's filesystem in CMake

I'm using the filesystem library from Boost in this project (https://github.com/marcomedrano1999/files_in_directory.git) and it works fine when I link the boost root to the proyect (I'm using Visual Studio), but I need it to be cross-platform so I implement the following in my CMakeLists.txt:
cmake_minimum_required(VERSION "3.18.3")
project("listdir")
find_package(Boost 1.73.0 REQUIRED filesystem)
include_directories("${Boost_INCLUDE_DIRS}")
link_directories("${Boost_LIBRARY_DIRS}")
add_executable("${PROJECT_NAME}" "Main.cpp")
target_link_libraries("${PROJECT_NAME}" ${Boost_LIBRARIES})
but when I tried to configure it in CMake the following error displayed:
CMake Error at C:/Program Files/CMake/share/cmake-3.18/Modules/FindPackageHandleStandardArgs.cmake:165 (message):
Could NOT find Boost (missing: filesystem) (found suitable version
"1.73.0", minimum required is "1.73.0")
Call Stack (most recent call first):
C:/Program Files/CMake/share/cmake-3.18/Modules/FindPackageHandleStandardArgs.cmake:458(_FPHSA_FAILURE_MESSAGE)
C:/Program Files/CMake/share/cmake-3.18/Modules/FindBoost.cmake:2177(find_package_handle_standard_args)
CMakeLists.txt:5 (find_package)
I'd tried several ways for this (as shown in the documentation page) but any of them have worked. Can someone tell me if I made something wrong?
If you have installed Boost library in a non-standard location, then you can specify the Boost Installation directory via BOOST_ROOT:
cmake -DBOOST_ROOT=<path to the boost installation directory> <... the rest of cmake options ...>
Also make sure that the filesystem part of boost is really installed (filesystem is a compiled library in contrast to other header only libraries).

CMake - Could NOT find Boost (missing: serialization) (found version "1.73.0"

I've been using Boost with my project for a while now, though until now, I'd only used the header-only libraries. I now want to use serialization, but when I try to add serialization as a REQUIRED component, I get the error written in the title.
Here is my CMAKE file:
cmake_minimum_required(VERSION 3.15)
project(GinRummyCPP)
SET(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "D:/Program Files/boost/boost_1_73_0")
SET(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "D:/Program Files/boost/boost_1_73_0/libs")
set(CMAKE_CXX_STANDARD 17)
find_package(Boost COMPONENTS serialization)
add_executable(GinRummyCPP main.cpp)
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
target_link_libraries(GinRummyCPP ${Boost_LIBRARIES})
endif()
I've checked my Boost folder, and serialization is at "D:\Program Files\boost\boost_1_73_0\libs\serialization"
I've tried setting BOOST_ROOT and other relevant variables, but nothing seems to work.
Here is the full error produced when loading the CMake file
CMake Warning at C:/Program Files/JetBrains/CLion 2019.3.2/bin/cmake/win/share/cmake-3.15/Modules/FindBoost.cmake:1144 (message):
New Boost version may have incorrect or missing dependencies and imported
targets
Call Stack (most recent call first):
C:/Program Files/JetBrains/CLion 2019.3.2/bin/cmake/win/share/cmake-3.15/Modules/FindBoost.cmake:1266 (_Boost_COMPONENT_DEPENDENCIES)
C:/Program Files/JetBrains/CLion 2019.3.2/bin/cmake/win/share/cmake-3.15/Modules/FindBoost.cmake:1904 (_Boost_MISSING_DEPENDENCIES)
CMakeLists.txt:7 (find_package)
-- Could NOT find Boost (missing: serialization) (found version "1.73.0")
-- Configuring done
-- Generating done
-- Build files have been written to: D:/Documents/GinRummyCPP/cmake-build-release-mingw-64
Not sure if it's relevant, but I'm using CLion as my IDE and mingw-w64 as my compiler.
I ended up using a C++ package manager called vcpkg to install Boost:x64-windows, and Boost and the appropriate components were properly found after that. The instructions for how to install it can be found here: https://github.com/Microsoft/vcpkg
After installing it, 64 bit Boost can be installed with the following command:
.\vcpkg.exe install boost:x64-windows
I still don't know what the original issue with CMake was, and I'm sure there was a way to fix it without using a package manager, but this is a solution for those that are okay with using a package manager.
EDIT
Found out this still didn't completely resolve my issue, and led to other problems. I found a complete solution that doesn't use a package manager and posted it in my answer to this question: Undefined reference errors in simple boost serialization

Building basic C++ project with boost python v1.67 and cmake on Ubuntu

This is my first attempt to write a cmake file for a production level project, I'm just trying to locate the boost python(v 1.67.0) package using cmake.
I have a very small CMakeLists.txt.
cmake_minimum_required(VERSION 3.13)
find_package(Boost 1.67.0 REQUIRED COMPONENTS system python37)
if(Boost_FOUND)
message("Boost_FOUND")
endif()
It works fine if I just try to find system but fails when I add python37. As per the FindBoost documentation, I need to mention it the way I have mentioned it. This is the output that I get:
CMake Error at /usr/share/cmake-3.13/Modules/FindBoost.cmake:2100 (message):
Unable to find the requested Boost libraries.
Boost version: 1.67.0
Boost include path: /usr/include
Could not find the following Boost libraries:
boost_python37
Some (but not all) of the required Boost libraries were found. You may
need to install these additional Boost libraries. Alternatively, set
BOOST_LIBRARYDIR to the directory containing Boost libraries or BOOST_ROOT
to the location of Boost.
Call Stack (most recent call first):
CMakeLists.txt:2 (find_package)
-- Configuring incomplete, errors occurred!
When I run $ locate libboost_python I get the following output:
/usr/lib/x86_64-linux-gnu/libboost_python-py27.so.1.65.1
/usr/lib/x86_64-linux-gnu/libboost_python27.so.1.67.0
/usr/lib/x86_64-linux-gnu/libboost_python3-py37.so.1.65.1
/usr/lib/x86_64-linux-gnu/libboost_python37.so.1.67.0
Given this output, I assume that the package/library is present.
So, I tried to add the following line in CMakeLists.txt:
set(BOOST_LIBRARYDIR "/usr/lib/x86_64-linux-gnu")
But the error remained. What am I missing here?
It looks like you are missing the dev package, as there is no /usr/lib/x86_64-linux-gnu/libboost_python27.so
Fix:
apt-get install libboost-python1.67-dev

Compiling C++ with Boost 1.68.0 on Windows using CMake and MinGW

I want to use the Boost library on Windows but doing so has been troublesome. I downloaded the Windows package from here and extracted it to C:\Boost:
I added the following to my CMake file:
find_package(Boost 1.68 REQUIRED COMPONENTS filesystem)
# ...
target_link_libraries(MyExecutable ${Boost_LIBRARIES})
I'm getting the following CMake error:
C:\Users\User\AppData\Local\JetBrains\Toolbox\apps\CLion\ch-0\183.4284.104\bin\cmake\win\bin\cmake.exe -DCMAKE_BUILD_TYPE=Debug "-DCMAKE_MAKE_PROGRAM=C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin/mingw32-make.exe" "-DCMAKE_C_COMPILER=C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin/x86_64-w64-mingw32-gcc.exe" "-DCMAKE_CXX_COMPILER=C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin/x86_64-w64-mingw32-g++.exe" -G "CodeBlocks - MinGW Makefiles" D:\Cpp\MyProject
CMake Error at C:/Users/User/AppData/Local/JetBrains/Toolbox/apps/CLion/ch-0/183.4284.104/bin/cmake/win/share/cmake-3.12/Modules/FindBoost.cmake:2048 (message):
Unable to find the requested Boost libraries.
Boost version: 1.68.0
Boost include path: C:/Boost
Could not find the following Boost libraries:
boost_filesystem
Some (but not all) of the required Boost libraries were found. You may
need to install these additional Boost libraries. Alternatively, set
BOOST_LIBRARYDIR to the directory containing Boost libraries or BOOST_ROOT
to the location of Boost.
Call Stack (most recent call first):
CMakeLists.txt:6 (find_package)
-- Configuring incomplete, errors occurred!
See also "D:/Cpp/MyProject/cmake-build-debug/CMakeFiles/CMakeOutput.log".
[Failed to reload]
It apparently cannot find filesystem but it's there in C:\Boost\boost\filesystem (here is the documentation on FindBoost).
How do I setup my CMake file to use Boost properly? I tried setting the Boost environment variables as well but it still didn't work:
SET (BOOST_ROOT "c:/Boost")
SET (BOOST_INCLUDEDIR "c:/Boost/boost")
SET (BOOST_LIBRARYDIR "c:/Boost/libs")
FIND_PACKAGE(Boost 1.68.0 REQUIRED COMPONENTS filesystem)
Also, Boost says that most things don't have to be compiled so I didn't do that.
It cannot find the library boost::filesystem. Because boost::filesystem is one of the few libraries that need to be compiled (all the ones that you have to specify in the find package command have to be compiled).
You need to build boost first:
./booststrap.sh
And then:
bjam
It picks up whatever compiler is available, so you may have to set the proper toolset manually.
Not completely related, but I think your link line is incorrect, instead of:
target_link_libraries(MyExecutable Boost::filesystem)
it should say:
target_link_libraries(MyExecutable ${Boost_LIBRARIES})
Boost_LIBRARIES is automatically defined once Boost is found, so it's for free.
The CMake FindBoost macro only fills Boost_Libraries if the find_package contains a COMPONENTS section and the macro actually finds those libraries on disk.
So here I'd be saying I need Boost to be found AND it must have filesystem
find_package(Boost 1.66.0 REQUIRED COMPONENTS filesystem)
The macro then tries to construct a bunch of potential filenames for the filesystem (taking into account if I want shared version, debug, multi-threaded etc.) and searches for those names under Boost_ROOT. If it doesn't find the file it may error and won't fill out Boost_Libraries.
If in doubt, add a line like this to your CMake prior to find_packages() to see what libs the macro is looking for and compare to what you actually have:
set (Boost_DEBUG ON)
For me I discovered that I had a Boost that placed an -x32 and -x64 architecture version of the libs, e.g. "libboost_system-mgw92-mt-x64-1_66.a". The macro wasn't filling in the architecture prefix into the filename it was looking for and failed.
I had to add a line like this to give the macro a clue which version I wanted:
set (Boost_ARCHITECTURE "-x64")
After that ${Boost_Libraries} expanded correctly and I was able to correctly use it to link.