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).
Related
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.
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
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.
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
I have compiled Boost from source with Visual Studio 2017, and I'm using CMake 3.9.3 to find it with the following command in my CMakeLists.txt:
find_package(Boost REQUIRED COMPONENTS filesystem)
I'm invoking CMake like this:
cmake -G "Visual Studio 15 2017" ..
-DBOOST_ROOT="C:\Users\emlai\src\libs\boost_1_65_0"
-DBOOST_LIBRARYDIR="C:\Users\emlai\src\libs\boost_1_65_0\lib64-msvc-15.0"
I get the following message:
CMake Error at C:/Program Files/CMake/share/cmake-3.9/Modules/FindBoost.cmake:1902 (message):
Unable to find the requested Boost libraries.
Boost version: 1.65.0
Boost include path: C:/Users/emlai/src/libs/boost_1_65_0
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:31 (find_package)
CMake Error at C:/Program Files/CMake/share/cmake-3.9/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
Could NOT find SDL2 (missing: SDL2_LIBRARY SDL2_INCLUDE_DIR)
Call Stack (most recent call first):
C:/Program Files/CMake/share/cmake-3.9/Modules/FindPackageHandleStandardArgs.cmake:377 (_FPHSA_FAILURE_MESSAGE)
build/cmake-modules/FindSDL2.cmake:173 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
CMakeLists.txt:42 (find_package)
-- Configuring incomplete, errors occurred!
See also "C:/Users/emlai/src/zenith/build/CMakeFiles/CMakeOutput.log".
See also "C:/Users/emlai/src/zenith/build/CMakeFiles/CMakeError.log".
The output of dir C:\Users\emlai\src\libs\boost_1_65_0\lib64-msvc-15.0 shows that the filesystem libraries are in place.
I have tried all of the answers here, but without success. The same happens with the prebuilt Boost libraries downloaded from here.
How can I solve this problem?
I needed to pass -DBoost_COMPILER="-vc141" to CMake to make it work (-vc141 being the same string as in the Boost library filenames).