I am trying to compile mlpack (http://www.mlpack.org/) which requires boost.
First I installed boostpro 1.51 (http://www.boostpro.com/download/) and boost is now installed in C:\Program Files\boost\boost_1_51
Then I compiled and installed armadillo (another dependancy of mlpack) using cmake and mingw32-make. Boost is also a dependency of armadillo. Following some advises (Cmake doesn't find Boost), I added to the CMakeLists file:
SET(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "C:\\Program Files\\boost\\boost_1_51")
SET(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "C:\\Program Files\\boost\\boost_1_51\\lib")
Things went smoothly.
Now I am trying to run CMake on mlpack but get this error:
CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/FindBoos
t.cmake:1192 (message):
Unable to find the requested Boost libraries.
Boost version: 1.51.0
Boost include path: C:/Program Files/boost/boost_1_51
The following Boost libraries could not be found:
boost_program_options
boost_unit_test_framework
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:192 (find_package)
I tried to add (as for armadillo), but no improvement:
SET(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "C:\\Program Files\\boost\\boost_1_51")
SET(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "C:\\Program Files\\boost\\boost_1_51\\lib")
Then I tried to add as well:
set(BOOST_ROOT "C:\\Program Files\\boost\\boost_1_51")
set(BOOST_INCLUDEDIR "C:\\Program Files\\boost\\boost_1_51")
set(BOOST_LIBRARYDIR "C:\\Program Files\\boost\\boost_1_51\\lib")
For the BOOST_INCLUDEDIR, I really do not know which folder I should point too. boost_1_51 contains: bin, boost, dist, doc, lib, libs, more
I also tried this (cmake is using the wrong cboost libs), without success.
I am also a little confused as armadillo seemed to have compiled without issues (or I missed something ?)
Many thanks
Note: content of the cmakelists file:
#Unfortunately this configuration variable is necessary and will need to be
#updated as time goes on and new versions are released.
set(Boost_ADDITIONAL_VERSIONS "1.41" "1.41.0" "1.42" "1.42.0" "1.43" "1.43.0" "1.44" "1.44.0" "1.45.0" "1.46.0" "1.46.1" "1.47.0" "1.48.0" "1.49.0" "1.51.0")
find_package(Boost
COMPONENTS
program_options
unit_test_framework
REQUIRED
)
include_directories(${Boost_INCLUDE_DIRS})
I added 1.51.0 myself.
from what I understood from another post (CMake not finding Boost) this might be related to not finding libraries with correct names. In my lib folder I have (dll and lib files):
boost_program_options-vc80-mt-1_51.dll
boost_program_options-vc80-mt-gd-1_51.dll
boost_program_options-vc100-mt-1_51.dll
boost_program_options-vc100-mt-gd-1_51.dll
somehow I am supposed to play with commands like
set(Boost_USE_MULTITHREADED ON)
so that it will look for the lib with the expected name ????
Related
I cannot get boost::asio to work with cmake in my c++ program. I have actually tried and googled for many hours, but I cannot get it to work!
I want to include boost::asio in my c++ Project under Ubuntu 18.04 with a cmake file.
So I installed the newest CMake (cmake version 3.19.4), and I downloaded boost version 1.74 and executed
./bootstrap.sh --prefix=/usr/
sudo ./b2 install
The install directory is /home/boost/boost_1_74_0. My CMake file looks like this:
cmake_minimum_required (VERSION 3.1.0)
# Project name
project (machine_tryout VERSION 1.0)
# Boost (header only)
#set(Boost_DEBUG 1)
set(BOOST_ROOT "$ENV{HOME}/boost/boost_1_74_0")
set(Boost_INCLUDE_DIR "$ENV{HOME}/boost/boost_1_74_0")
set(Boost_LIBRARY_DIR "$ENV{HOME}/boost/boost_1_74_0/libs")
find_package(Boost REQUIRED Components asio)
# Set Executable
add_executable(${PROJECT_NAME} source/tryout.cpp)
But everything I get is the following:
vm-umic#vm:~/Projects/tryout/build$ cmake ..
CMake Warning at /snap/cmake/775/share/cmake-3.19/Modules/FindBoost.cmake:2034 (message):
No header defined for asio; skipping header check (note: header-only
libraries have no designated component)
Call Stack (most recent call first):
CMakeLists.txt:27 (find_package)
CMake Error at /snap/cmake/775/share/cmake-3.19/Modules/FindPackageHandleStandardArgs.cmake:218 (message):
Could NOT find Boost (missing: asio) (found version "1.74.0")
Call Stack (most recent call first):
/snap/cmake/775/share/cmake-3.19/Modules/FindPackageHandleStandardArgs.cmake:582 (_FPHSA_FAILURE_MESSAGE)
/snap/cmake/775/share/cmake-3.19/Modules/FindBoost.cmake:2193 (find_package_handle_standard_args)
CMakeLists.txt:27 (find_package)
-- Configuring incomplete, errors occurred!
See also "/home/vm-umic/Projects/tryout/build/CMakeFiles/CMakeOutput.log".
What in the world am I doing wrong? Isnt CMake telling me that it found Boost 1.74? CMake does NOT throw any errors if I try find_package(Boost REQUIRED), but then linking does also not work. I explicitly tell CMake where to find the libraries, so why can't CMake finde Boost?
Try this.
cmake_minimum_required (VERSION 3.1.0)
# Project name
project (machine_tryout VERSION 1.0)
# Boost (header only)
#set(Boost_DEBUG 1)
set(BOOST_ROOT "$ENV{HOME}/boost/boost_1_74_0")
set(Boost_INCLUDE_DIR "$ENV{HOME}/boost/boost_1_74_0")
set(Boost_LIBRARY_DIR "$ENV{HOME}/boost/boost_1_74_0/libs")
find_package(Boost REQUIRED Components system)
# Set Executable
add_executable(${PROJECT_NAME} source/tryout.cpp)
target_link_libraries(${PROJECT_NAME}
${Boost_LIBRARIES})
I just had a similar problem, and found that I had missed a small but important step in the Boost installation: adding the installation directory (i.e. the PREFIX used in b2 install --prefix=PREFIX) to the PATH environment variable.
For me, this solved it – hopefully will for you too!
I am new to C++ and want to include the boost library (specifically the filesystem part which needs to be built) in my project. I tried many solutions from other stackoverflow users but they didn't help me at all. I am using CLion with CMake.
The main.cpp is calling the other .cpp files inside the modules/ folder.
The file structure:
ProjectName
>boost
>lots of folders and .hpp files
>cmake-build-debug
>modules
encryption.cpp
encryption.h
output.cpp
output.h
CMakeLists.txt
main.cpp
The boost folder doesn't contain the entirety of boost when you download and extract it. I dragged the boost folder inside of boost_1_72_0 in my project (just so you know that there's no libs folder, etc. inside)
The CMakeLists.txt
cmake_minimum_required(VERSION 3.14)
project(ProjectName)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libstdc++ -static-libgcc")
set(SOURCE_FILES
main.cpp
modules/encryption.cpp modules/encryption.h modules/output.cpp modules/output.h
)
set(Boost_ARCHITECTURE -x64)
set(BOOST_ROOT boost/)
set(Boost_INCLUDE_DIRS boost/filesystem)
find_package(Boost COMPONENTS system filesystem REQUIRED)
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
endif()
add_executable(ProjectName ${SOURCE_FILES})
target_link_libraries(ProjectName ${Boost_LIBRARIES})
output.cpp
// some includes //
#define BOOST_FILESYSTEM_NO_DEPRECATED
#include "../boost/filesystem.hpp"
// some code //
The Error message:
CMake Error at C:/Program Files/JetBrains/CLion 2019.1.4/bin/cmake/win/share/cmake-3.14/Modules/FindBoost.cmake:2147 (message):
Unable to find the requested Boost libraries.
Unable to find the Boost header files. Please set BOOST_ROOT to the root
directory containing Boost or BOOST_INCLUDEDIR to the directory containing
Boost's headers.
Call Stack (most recent call first):
CMakeLists.txt:15 (find_package)
-- Configuring incomplete, errors occurred!
See also "C:/Users/username/Desktop/C++/ProjectName/cmake-build-debug/CMakeFiles/CMakeOutput.log".
mingw32-make.exe: *** [cmake_check_build_system] Error 1
Makefile:235: recipe for target 'cmake_check_build_system' failed
I know that it's basically telling me what I have to do but I don't know what's exactly meant by the "root directory" of boost, by the directory "containing Boost's headers" and how to put everything together.
Many thanks in advance!
I dragged the boost folder inside of boost_1_72_0 in my project
Looks like you just copied boost source into your project dir.
You have to compile boost since you need filesystem. Or you can get boost from:
vcpkg - it's the easiest way for you. I am highly recommended this way.
Sourceforge.
Conan
I don't know what's exactly meant by the "root directory"...
Since you are using boost by calling find_package(Boost) - CMake uses FindBoost module. It will try to find your boost installation inside system PATH variable or in some other "standard" places. Your boost "installation" is not common, so you have to specify where boost is with BOOST_ROOT variable. set(BOOST_ROOT boost/) is incorrect way to do this. You have to specify absolute path like set(BOOST_ROOT "C:/lib/boost/boost17.2")
or relative to current CMakeList.txt - set(BOOST_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/boost}.
With right installed boost all you have to do is:
find_package(Boost REQUIRED [COMPONENTS <libs>...])
target_link_libraries(main PRIVATE ${Boost_LIBRARIES})
target_include_directories(main PRIVATE ${Boost_INCLUDE_DIRS})
Usually, you don't need to set Boost_ARCHITECTURE and Boost_INCLUDE_DIRS CMake does it for you.
When you use find_package with REQUIRED option you don't need to check whether the library found or not since CMake raises an error when a library isn't found.
BOOST_ROOT is a directory when boost installed or unpacked.
BOOST_INCLUDEDIR is a directory with boost headers (usually it's BOOST_ROOT/boost). So try to set the full path to your boost_1_72_0 directory to BOOST_ROOT CMake variable.
Also, I had a problem with COMPONENTS option. Try to remove it if errors remain.
I am trying to use boost thread for my project in a Ubuntu machine. I download boost 1.58.0 via apt-get in ubuntu and use Cmake for building the c++ project.
In my CMakeLists.txt, I have
find_package(Boost 1.58.0 REQUIRED)
include_directories( ${Boost_INCLUDE_DIR} )
message(STATUS "Boost_INCLUDE_DIR: ${Boost_INCLUDE_DIR}")
message(STATUS "Boost_LIBRARIES: ${Boost_LIBRARIES}")
target_link_libraries( Sparse3D ${COLMAP_LIBRARIES} )
It turns out Cmake can't find the boost library
-- Boost_INCLUDE_DIR: /usr/include
-- Boost_LIBRARIES:
I then checked online and figured out that I may need to specify the library, and changed the CMakeLists.txt to
find_package(Boost 1.58.0 COMPONENTS system filesystem thread REQUIRED)
But CMake can't find boost_thread. Here is the CMake output:
-- Found Glew
-- Includes : /usr/include
-- Libraries : /usr/lib/x86_64-linux-gnu/libGLEW.so
-- __cplusplus is 201103
-- --> Do not link with Boost.Thread
-- Boost version: 1.58.0
-- Boost include dirs: /usr/include
-- Boost libraries:
CMake Error at /usr/share/cmake-3.5/Modules/FindBoost.cmake:1677 (message):
Unable to find the requested Boost libraries.
Boost version: 1.58.0
Boost include path: /usr/include
Could not find the following Boost libraries:
boost_thread
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:20 (find_package)
-- GLM_INCLUDE_DIR = /usr/local/include
-- GLM included at /usr/local/include
-- Boost_LIBRARIES: /usr/include
-- Boost_LIBRARIES:
But libboost_thread.so.1.58.0 does exist in /usr/lib/x86_64-linux-gnu.
Thank you all in advance.
I again did a fresh installation of boost 1.71, and suddenly CMake is able to find libboost-thread. What I found is that CMake findpackage can't find libboost-thread with boost 1.58 (installed with apt-get), but can find that with boost 1.71. Previously, I guess it's probably because boost 1.58 was not removed completely which causes CMake to fail to find boost-thread 1.71. Besides, even though boost 1.51 is removed, CMake can still find boost 1.48 in ubuntu.
I successfully build my project on locale machine, but when i upload my build in Travis i see this:
CMake Error at /usr/share/cmake-3.2/Modules/FindBoost.cmake:1182
(message):
Unable to find the requested Boost libraries.
Boost version: 1.46.1
Boost include path: /usr/include
Could not find the following static Boost libraries:
boost_log
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:18 (find_package)
-- Configuring incomplete, errors occurred!
I many time search this error in google, but i not found answer. My CMakeList file this:
cmake_minimum_required(VERSION 3.2)
project(Recast-server)
set(CMAKE_CXX_STANDARD 14)
file(GLOB_RECURSE SOURCE_FILES
"src/*.h"
"src/*.c"
"src/*.cpp")
include_directories(src/headers/)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
add_definitions(-DBOOST_LOG_DYN_LINK)
find_package(Boost 1.46 COMPONENTS system
thread
log
log_setup
program_options
filesystem
REQUIRED)
include_directories(${Boost_INCLUDE_DIR})
add_executable(Recast-server ${SOURCE_FILES})
target_link_libraries(Recast-server ${Boost_LIBRARIES})
target_link_libraries(Recast-server ${CMAKE_THREAD_LIBS_INIT})
You can ask(or try commit) also in this PullRequest: https://github.com/bender-wardrobe/Recast/pull/15
Big Thanks for your answer <3
If I remember correctly Boost.Log was only added in later versions of Boost.
For earlier versions of Boost you can use the standalone Boost.Log from http://boost-log.sf.net
edit
You set the version 1.46 in your CMakeLists.txt. Maybe try a later version. Don't know about Travis.
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.