I tried to use conan to integrate boost into my cpp Projekt.
While it seems conan does install the boost libraries, CMake says
-- Could NOT find Boost (missing: Boost_INCLUDE_DIR) (Required is at least version "1.78.0")
For the basic setup I tried to follow: https://codetrips.com/2020/03/20/1198/
And I found the question CMake not finding boost libraries from conan, but since the setup seems to be a bit different (and no solution was found), I would like to present my problem and project.
My project layout is:
- ${project_root}/CMakeLists.txt
- ${project_root}/conanfile.txt
- ${project_root}/main.cpp
- ${project_root}/build
With CMakeLists.txt:
cmake_minimum_required(VERSION 3.16)
project(boost_process_test)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
find_package(Boost 1.78.0)
add_executable(test main.cpp)
target_link_libraries(test PRIVATE Boost)
and with conanfile.txt
[requires]
boost/1.78.0
[generators]
cmake
and with main.cpp
#include <boost/process.hpp>
int main() {
return 0;
}
Within the build directory I called
$ conan install ..
yielding the output:
Configuration:
[settings]
...
build_type=Release
...
boost/1.78.0 from 'conancenter' - Cache
When calling
$ cmake -DCMAKE_BUILD_TYPE=Release ..
the above stated output is yielded.
Related
I have installed boost-variant2 library using the vcpkg command:
vcpkg install boost-variant2:x64-windows
When vcpkg finished the installation, it prompted this:
The package boost is compatible with built-in CMake targets:
find_package(Boost REQUIRED [COMPONENTS <libs>...])
target_link_libraries(main PRIVATE Boost::boost Boost::<lib1> Boost::<lib2> ...)
so in my CMakeLists.txt I added the following lines:
find_package(Boost COMPONENTS variant2 REQUIRED)
target_link_libraries(MyTarget PRIVATE Boost::variant2)
However, when I run cmake -DCMAKE_TOOLCHAIN_FILE:STRING=/path_to_vcpkg/scripts/buildsystems/vcpkg.cmake I get the following error:
-- Configuring incomplete, errors occurred!
Could NOT find Boost (missing: variant2) (found version "1.78.0")
Looks like variant2 is header-only lib and you can just use Cmake file like this:
cmake_minimum_required(VERSION 3.5)
project(project LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Boost)
include_directories(${Boost_INCLUDE_DIRS})
add_executable(project main.cpp)
U can see list of libs required to be built for here for Windows and here for Unix-like systems
I want to compile SealPIR library using emscripten to generate a wasm file.
When using this command:
emcmake cmake .
I get this error:
CMake Error at CMakeLists.txt:19 (find_package):
By not providing "FindSEAL.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "SEAL", but
CMake did not find one.
Could not find a package configuration file provided by "SEAL" (requested
version 3.2.0) with any of the following names:
SEALConfig.cmake
seal-config.cmake
Add the installation prefix of "SEAL" to CMAKE_PREFIX_PATH or set
"SEAL_DIR" to a directory containing one of the above files. If "SEAL"
provides a separate development package or SDK, be sure it has been
installed.
-- Configuring incomplete, errors occurred!
See also "/home/Zied/webassembly/SealPIR/CMakeFiles/CMakeOutput.log".
emcmake: error: 'cmake . -DCMAKE_TOOLCHAIN_FILE=/home/Zied/webassembly/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake -DCMAKE_CROSSCOMPILING_EMULATOR="/home/Zied/webassembly/emsdk/node/14.15.5_64bit/bin/node"' failed (1)
SEAL is correctly installed. when i run the same command without emcmake it works just fine.
This is my CMakeList
cmake_minimum_required(VERSION 3.10)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
project(SealPIR VERSION 2.1 LANGUAGES CXX)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
add_executable(main
main.cpp
)
add_library(sealpir STATIC
pir.cpp
pir_client.cpp
pir_server.cpp
)
find_package(SEAL 3.2.0 EXACT REQUIRED)
target_link_libraries(main sealpir SEAL::seal)
When using a toolchain file for cross compiling, CMake will by default disable system libraries. It won't search into any directory to avoid finding files that is not compatible with the target system.
You think you didn't used a toolchain file? Think again! emcmake hides that from you. Look carefully at the error output.
Here you compiled the SEAL library, but you installed it in the default path, which is /usr/local.
We can tell CMake to explicitly search there, but I wouldn't recommend, but you can try if it works:
emcmake cmake . -CMAKE_PREFIX_PATH=/usr/local
The proper solution would be to create a directory with all the emscripten libraries in it:
# In the SEAL build directory
emcmake cmake .. -DCMAKE_INSTALL_PREFIX=/home/anblic/webassembly/install
Then after installing the libraries in that directory, you can set the prefix path in the same directory as the install path:
# Assuming you're in a build/ subdirectory
emcmake cmake .. -DCMAKE_PREFIX_PATH=/home/anblic/webassembly/install
I'm trying to use fltk library in my project but I have some troubles.
Here is my CMakeLists.txt file:
cmake_minimum_required(VERSION 3.12)
project(pp)
set(CMAKE_CXX_STANDARD 14)
add_executable(pp main.cpp)
FIND_PACKAGE(FLTK REQUIRED)
FIND_PACKAGE(GTK REQUIRED)
TARGET_LINK_LIBRARIES(pp ${FLTK_LIBRARIES})
TARGET_LINK_LIBRARIES(pp ${GTK_LIBRARIES})
FLTK version: 1.3.4
Cmake version: 3.7.2
I have installed fltk library in my /usr/local dirs
Include files are located in /usr/local/include/FL
I saw that the FindFLTK.cmake looks for following files:
FL/Fl.h or FL/Fl.H which the FL/Fl.h is located in /usr/local/include/FL so it can be found.
Here is the error message:
Could NOT find FLTK (missing: FLTK_INCLUDE_DIR)
Have you any ideas to solve this problem?
UPDATE
Current version of CMakeLists.txt
cmake_minimum_required(VERSION 3.7.2)
project(pp)
set(CMAKE_CXX_STANDARD 14)
add_executable(pp main.cpp)
target_include_directories(pp PRIVATE /usr/local/include/FL)
set (LIBRARIES fltk Xrender Xcursor Xfixes Xext Xft fontconfig Xinerama pthread dl m X11)
message(STATUS mess: ${CMAKE_MODULE_PATH})
target_link_libraries(pp ${LIBRARIES})'
In this configuration I can compile, and link executable, but why configuration with FIND_PACKAGE does not work? Where I should look for a bug?
Probably bad installation of library. I just installed fresh one from GitHub sources with CMake configuring by cmake -G "MinGW Makefiles" . with followed make and make install to install it in compiler library I suppose.
After that errors containing Could NOT find FLTK (missing: FLTK_INCLUDE_DIR) has disappeared in compilation of another project. I suppose, cmake error report is not so strict and clarified, i.e. this error means some exception in FindFLTK.cmake and not exactly about missing FLTK_INCLUDE_DIR.
I am not a C++ programmer, only have made a course a while ago. Using homebrew I installed libbitcoin and was hoping that I can reference the library like I was able to reference the boost libraries. I also realized that there are no links in /usr/local/bin to the Cellar.
I think I could get it working by using the absolute paths but I am looking for the proper way of handling this constellation that I just mentioned.
Current CMake:
cmake_minimum_required(VERSION 2.8.4)
project(cplusplus)
message(STATUS "start running cmake...")
find_package(boost 1.65.1 COMPONENTS system filesystem REQUIRED)
find_package(libbitcoin 3.3.0 COMPONENTS system filesystem REQUIRED)
message("system: ${CMAKE_SYSTEM_PREFIX_PATH}")
find_library(LIB_BITCOIN libbitcoin)
message("bitcoin: ${LIB_BITCOIN}")
if(Boost_FOUND)
message(STATUS "Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}")
message(STATUS "Boost_LIBRARIES: ${Boost_LIBRARIES}")
message(STATUS "Boost_VERSION: ${Boost_VERSION}")
include_directories(${Boost_INCLUDE_DIRS})
endif()
add_executable(cplusplus main.cpp)
if(Boost_FOUND)
target_link_libraries(cplusplus ${Boost_LIBRARIES})
endif()
Currently I get these errors:
/Applications/CLion.app/Contents/bin/cmake/bin/cmake -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - Unix Makefiles" /Users/johndow/Documents/Workspace/bitcoin-code/cplusplus
-- start running cmake...
-- Boost version: 1.65.1
CMake Error at CMakeLists.txt:8 (find_package):
By not providing "Findlibbitcoin.cmake" in CMAKE_MODULE_PATH this project
has asked CMake to find a package configuration file provided by
"libbitcoin", but CMake did not find one.
Could not find a package configuration file provided by "libbitcoin"
(requested version 3.3.0) with any of the following names:
libbitcoinConfig.cmake
libbitcoin-config.cmake
Add the installation prefix of "libbitcoin" to CMAKE_PREFIX_PATH or set
"libbitcoin_DIR" to a directory containing one of the above files. If
"libbitcoin" provides a separate development package or SDK, be sure it has
been installed.
-- Configuring incomplete, errors occurred!
See also "/Users/johndoe/Documents/Workspace/bitcoin-code/cplusplus/cmake-build-debug/CMakeFiles/CMakeOutput.log".
[Finished]
You seem to have double lookup for libbitcoin library in your CMakeLists file. You are first looking for it by:
find_package(libbitcoin ...)
and then by
find_library(LIB_BITCOIN libbitcoin)
Cmake is not happy (as your error message says) with the find_package() clause as libbitcoin does not provide cmake configuration by itself. You have many ways how to fix it, just two of them:
remove find_package() and use only find_library(), I think this is the simpler way and your project should work this way
provide cmake configuration for libbitcoin by yourself. Good introduction how to do this is here (and good to read anyway):
https://cmake.org/Wiki/CMake:How_To_Find_Libraries
As far as I know, currently libbitcoin does not export any <libbitcoin>Config.cmake package.
But it does export a libbitcoin.pc file for generic use with pkg-config.
ie: /usr/local/lib/pkgconfig/libbitcoin.pc
If you get results from invoking pkg-config --cflags libbitcoin then it's there.
And then you can put something like this in your CMakeLists.txt:
#use this if libbitcoin is installed to some custom location
set(ENV{PKG_CONFIG_PATH} "/path/to/libbitcoin/pkgconfig/:$ENV{PKG_CONFIG_PATH}")
#then later..
find_package(PkgConfig REQUIRED)
pkg_check_modules(LIB_BITCOIN REQUIRED libbitcoin)
#then later..
target_link_libraries(${PROJECT_NAME} PRIVATE ${LIB_BITCOIN_LIBRARIES})
target_include_directories(${PROJECT_NAME} PRIVATE ${LIB_BITCOIN_INCLUDE_DIRS})
That should pull in boost, make the libbitcoin includes visible and solve all manner of compiler and linker woes.
(Or if you are feeling mad, you could always make use of this gist).
I am new to C/C++, Cmake, and Boost; I've read every post in SO of other people having my same problem and I couldn't figure it out.
EDIT: as explained in the comment, I already read another similar post, and I'm already doing what is proposed in the accepted solution (i.e. using COMPONENTS libraryName and set(Boost_USE_STATIC_LIBS OFF). Actually, putting Boost_USE_STATIC_LIBS to OFF removed the "lib" prefix from the libraries name in the argn parameter. And I seem to need that prefix..
I built Boost for Android with bjam and, hoping that I have done everything correctly, I used this command:
./b2 install include=/home/myUser/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include include=/home/myUser/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/include include=/home/myUser/android-ndk-r12b/platforms/android-19/arch-arm/usr/include toolset=gcc-arm target-os=android --prefix=/home/myUser/boost_build --with-system --with-random --with-date_time -sNO_BZIP2=1 link=static runtime-link=shared threading=multi
And I end up with this folder structure:
/home/myUser/boost_build/
- include/
-boost/
- # a lot of folders and .hpp files
- lib/
- libboost_date_time.a
- libboost_random.a
- libboost_system.a
Then I launch Cmake in order to compile my project with this command:
cmake -DBOOST_ROOT=/home/myUser/boost_build -DBOOST_INCLUDEDIR=/home/myUser/boost_build/include -DBOOST_LIBRARYDIR=/home/myUser/boost_build/lib -DBOOST_VER:STRING=1.61.0 ./
And this is the revelant part of CMakeList.txt:
option(BUILD_SHARED_LIBS "Build the shared library" OFF)
#option(Boost_USE_STATIC_LIBS "Use Boost static version" ON)
set(Boost_USE_STATIC_LIBS ON)
#tried both of the versions above, I don't even know the difference
set(BOOST_VER "1.61.0")
set(Boost_VERSION 106100)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
set(Boost_FIND_QUIETLY 0 )
set(Boost_DEBUG 1)
find_package(Boost ${BOOST_VER} REQUIRED COMPONENTS system date_time random)
Finally, I end up with this error:
-- [ /usr/share/cmake-3.5/Modules/FindBoost.cmake:1558 ] Boost_FOUND = 1
# e.d.: Notice that Boost_FOUND = 1. Reading through the FindBoost code, I understand that this means that he found the include directory with the header files.
CMake Error at /usr/share/cmake-3.5/Modules/FindBoost.cmake:1719 (message):
# e.d.: don't mind the line numbers in the FindBoost.cmake files... I added a lot of messages around, to debug
Unable to find the requested Boost libraries.
Boost version: 1.61.0
Boost include path: /home/myUser/boost_build/include
Could not find the following static Boost libraries:
boost_system
boost_date_time
boost_random
No Boost libraries were found. You may need to 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:48 (find_package)
If I try to print the find_library parameters, in FindBoost.cmake:
message(STATUS "looking for library: var: ${var} , dollarvar: ${${var}}, argn: ${ARGN}")
find_library(${var} ${ARGN})
message(STATUS "dollarvar: ${${var}}" )
I get:
-- looking for library: var: Boost_SYSTEM_LIBRARY_RELEASE , dollarvar: , argn: NAMES;libboost_system-ghs-mt-1_61;libboost_system-ghs-mt;libboost_system-mt-1_61;libboost_system-mt;libboost_system;HINTS;/home/myUser/boost_build/lib;/home/myUser/boost_build/lib;/home/myUser/boost_build/stage/lib;/home/myUser/boost_build/include/lib;/home/myUser/boost_build/include/../lib;/home/myUser/boost_build/include/../lib/;/home/myUser/boost_build/include/stage/lib;PATHS;C:/boost/lib;C:/boost;/sw/local/lib;NAMES_PER_DIR;DOC;Boost system library (release)
-- dollarvar: Boost_SYSTEM_LIBRARY_RELEASE-NOTFOUND
EDIT2: I tried to copypaste my boost_build directory and my project directory from Linux to Windows, where I installed CMake too, and with my great annoyance... cmake under windows worked. Unfortunately cmake under windows generates some Visual Studio Project files, instead of a makefile. Now I'm wondering why cmake version 3.5.1 under Ubuntu 16.04 doesn't work, and cmake version 3.6.2 under Windows 7 does.