Cmake can't find boost thread library - c++

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.

Related

Could not find the following Boost libraries: boost_fiber

I'm not familiar with boost. And I want to use the class in boost,like boost::context::fiber and boost::context::continuation. So, I download the newest version of boost 1.68. Build it by the instruction in official site.
First, run bootstrap and generate b2 file.
$ ./bootstrap.sh --with-libraries=all --prefix=/usr/local/boost_168_build
Then run it with install.
#--:/usr/local/boost_1_68_0$ ./b2 --show-libraries
The following libraries require building:
- atomic
- chrono
- container
- context
- contract
- coroutine
- date_time
- exception
- fiber
- filesystem
- graph
- graph_parallel
- iostreams
- locale
- log
- math
- mpi
- program_options
- python
- random
- regex
- serialization
- signals
- stacktrace
- system
- test
- thread
- timer
- type_erasure
- wave
#--:/usr/local/boost_1_68_0$ sudo ./b2 install
And I make a cmake project create a Cmakelist.
cmake_minimum_required(VERSION 3.12)
project(boost_context)
set(Boost_USE_STATIC_LIBS OFF) # only find static libs
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
set(CMAKE_CXX_STANDARD 11)
set (BOOST_ROOT
"/usr/local/boost_1_68_0")
set (BOOST_LIBRARYDIR
"/usr/local/boost_1_68_0/lib")
find_package( Boost REQUIRED COMPONENTS context fiber)
if(Boost_FOUND)
ADD_DEFINITIONS( "-DHAS_BOOST" )
message(STATUS ${Boost_INCLUDE_DIRS})
# include_directories(${Boost_INCLUDE_DIRS})
message(STATUS ${Boost_LIBRARIES})
message(STATUS ${BOOST_LIBRARYDIR})
message(STATUS ${Boost_LIBRARIES})
message(STATUS ${Boost_LIBRARIES})
message(STATUS ${Boost_LIBRARIES})
endif()
add_executable(boost_context main.cpp)
But when I turn on Boost_USE_STATIC_LIBS
cmake will report:
/clion-2018.2.5/bin/cmake/linux/bin/cmake -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - Unix Makefiles"
/Other_Project/boost-context
CMake Error at /clion-2018.2.5/bin/cmake/linux/share/cmake-
3.12/Modules/FindBoost.cmake:2048 (message):
Unable to find the requested Boost libraries.
Boost version: 1.68.0
Boost include path: /usr/local/boost_168_build/include
Could not find the following static Boost libraries:
boost_fiber
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:15 (find_package)
Turn off the Boost_USE_STATIC_LIBS
cmake will report:
/clion-2018.2.5/bin/cmake/linux/bin/cmake -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - Unix Makefiles" /Other_Project/boost-context
CMake Error at /clion-2018.2.5/bin/cmake/linux/share/cmake-3.12/Modules/FindBoost.cmake:2048 (message):
Unable to find the requested Boost libraries.
Boost version: 1.68.0
Boost include path: /usr/local/boost_168_build/include
Could not find the following Boost libraries:
boost_fiber
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:15 (find_package)
At last, you know what I really confused about why I can find that???
#--0:/usr/local/boost_168_build/include/boost/fiber$ pwd
/usr/local/boost_168_build/include/boost/fiber
#--0:/usr/local/boost_168_build/include/boost/fiber$ ls
algo condition_variable.hpp fiber.hpp hip pooled_fixedsize_stack.hpp scheduler.hpp
all.hpp context.hpp fixedsize_stack.hpp mutex.hpp properties.hpp segmented_stack.hpp
barrier.hpp cuda fss.hpp numa protected_fixedsize_stack.hpp timed_mutex.hpp
buffered_channel.hpp detail future operations.hpp recursive_mutex.hpp type.hpp
channel_op_status.hpp exceptions.hpp future.hpp policy.hpp recursive_timed_mutex.hpp unbuffered_channel.hpp
But there is nothing fiber or continuation in lib
#--0:/usr/local/boost_168_build/lib$ pwd
/usr/local/boost_168_build/lib
#--0:/usr/local/boost_168_build/lib$ ls
libboost_atomic.a libboost_iostreams.so libboost_numpy27.a libboost_stacktrace_backtrace.so.1.68.0
libboost_atomic.so libboost_iostreams.so.1.68.0 libboost_numpy27.so libboost_stacktrace_basic.a
libboost_atomic.so.1.68.0 libboost_locale.a libboost_numpy27.so.1.68.0 libboost_stacktrace_basic.so
libboost_chrono.a libboost_locale.so libboost_prg_exec_monitor.a libboost_stacktrace_basic.so.1.68.0
libboost_chrono.so libboost_locale.so.1.68.0 libboost_prg_exec_monitor.so libboost_stacktrace_noop.a
libboost_chrono.so.1.68.0 libboost_log.a libboost_prg_exec_monitor.so.1.68.0 libboost_stacktrace_noop.so
libboost_container.a libboost_log_setup.a libboost_program_options.a libboost_stacktrace_noop.so.1.68.0
libboost_container.so libboost_log_setup.so libboost_program_options.so libboost_system.a
libboost_container.so.1.68.0 libboost_log_setup.so.1.68.0 libboost_program_options.so.1.68.0 libboost_system.so
libboost_context.a libboost_log.so libboost_python27.a libboost_system.so.1.68.0
libboost_context.so libboost_log.so.1.68.0 libboost_python27.so libboost_test_exec_monitor.a
libboost_context.so.1.68.0 libboost_math_c99.a libboost_python27.so.1.68.0 libboost_thread.a
libboost_contract.a libboost_math_c99f.a libboost_random.a libboost_thread.so
libboost_contract.so libboost_math_c99f.so libboost_random.so libboost_thread.so.1.68.0
libboost_contract.so.1.68.0 libboost_math_c99f.so.1.68.0 libboost_random.so.1.68.0 libboost_timer.a
libboost_coroutine.a libboost_math_c99l.a libboost_regex.a libboost_timer.so
libboost_coroutine.so libboost_math_c99l.so libboost_regex.so libboost_timer.so.1.68.0
libboost_coroutine.so.1.68.0 libboost_math_c99l.so.1.68.0 libboost_regex.so.1.68.0 libboost_type_erasure.a
libboost_date_time.a libboost_math_c99.so libboost_serialization.a libboost_type_erasure.so
libboost_date_time.so libboost_math_c99.so.1.68.0 libboost_serialization.so libboost_type_erasure.so.1.68.0
libboost_date_time.so.1.68.0 libboost_math_tr1.a libboost_serialization.so.1.68.0 libboost_unit_test_framework.a
libboost_exception.a libboost_math_tr1f.a libboost_signals.a libboost_unit_test_framework.so
libboost_filesystem.a libboost_math_tr1f.so libboost_signals.so libboost_unit_test_framework.so.1.68.0
libboost_filesystem.so libboost_math_tr1f.so.1.68.0 libboost_signals.so.1.68.0 libboost_wave.a
libboost_filesystem.so.1.68.0 libboost_math_tr1l.a libboost_stacktrace_addr2line.a libboost_wave.so
libboost_graph.a libboost_math_tr1l.so libboost_stacktrace_addr2line.so libboost_wave.so.1.68.0
libboost_graph.so libboost_math_tr1l.so.1.68.0 libboost_stacktrace_addr2line.so.1.68.0 libboost_wserialization.a
libboost_graph.so.1.68.0 libboost_math_tr1.so libboost_stacktrace_backtrace.a libboost_wserialization.so
libboost_iostreams.a libboost_math_tr1.so.1.68.0 libboost_stacktrace_backtrace.so libboost_wserialization.so.1.68.0
Could somebody tell me where i missed. Thanks
You can use use:
b2 cxxflags="-std=c++14" --reconfigure --with-fiber
to compile the libboost_fiber.a
fiber is a header only library, so nothing to link against and no need to add it as a component to find.
The list of compiled libraries is in the doc: https://www.boost.org/doc/libs/1_68_0/more/getting_started/unix-variants.html#header-only-libraries

Why boost log not found?

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.

How could I link the Boost (not in usr/include) in CMakeList.txt using find_package

Now, I need to use " find_package(Boost 1.62.0 COMPONENTS program_options serialization system filesystem thread REQUIRED)" to include some libs into my program, but my boost library is installed in other directory, not in the defualt directory**(usr/include..)**. Now it occurs the following errors:
CMake Error at /usr/share/cmake/Modules/FindBoost.cmake:1138 (message):
Unable to find the requested Boost libraries.
Boost version: 1.41.0
Boost include path: /usr/includ
Detected version of Boost is too old.
Requested version was 1.62 (or
newer).
I give out some contents of my CMakelist.txt:
SET(BOOST_DIR /home/mingjli/folder_Mingjie/Software/boost_1.62.0/include/boost)
SET(BOOST_LIB /home/mingjli/folder_Mingjie/Software/boost_1.62.0/lib)
INCLUDE (${Source_Path}/IndexerLauncher.cmake NO_POLICY_SCOPE)
INCLUDE_DIRECTORIES(${BOOST_DIR})
LINK_DIRECTORIES(${BOOST_LIB})
INCLUDE_DIRECTORIES(${Source_Path})
ADD_EXECUTABLE (indexer_launcher ${IndexerLauncher})
TARGET_LINK_LIBRARIES (indexer_launcher nearest_search_lib)
target_link_libraries( indexer_launcher ${Boost_LIBRARIES} )
Thank you!!
Boost version: 1.41.0
^^
This means, that you have boost version 1.41.0 installed, but you are requesting 1.62.0. You can update boost or change minimal boost version requirements:
find_package(Boost 1.41.0 COMPONENTS program_options serialization system filesystem thread REQUIRED)
^^
There is nothing really special you should have in your CMakeLists.txt to include Boost. Here is a sample that works for me:
cmake_minimum_required(VERSION 2.8)
find_package(Boost REQUIRED filesystem system)
include_directories(${Boost_INCLUDE_DIRS})
target_link_libraries(mytarget ${Boost_LIBRARIES})
UPDATE:
If you can't update your system boost version, you can install boost into your home folder:
download boost sources from www.boost.org
compile and install new boost into your home directory:
b2 toolset=gcc install --prefix=/home/user/boost
After boost is compiled - you can use it from /home/user/boost:
cmake .. -DBOOST_ROOT=/home/user/boost

Cmake cannot find boost libraries; but includedir and librarydir are set

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.

Cmake does not find boost 1.51 (windows 8)

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 ????