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
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 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.
H-e-l-l-o everyone.
I try to build my c++-project with cmake and boost 1.67 in travis-ci.
Below are the source files.
On my linux-computer are installed cmake 3.13.4 from sources and a boost-1.67 from the sources, all the libraries (statically and dynamic) are in the directory "/usr/local/lib/" and all works fine. But in travis-ci I every time see this message:
Unable to find the requested Boost libraries.
Boost version: 1.67.0
Boost include path: /usr/include
Could not find the following static Boost libraries:
boost_program_options
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.
yml file:
language: cpp
dist: xenial
sudo: false
os: linux
matrix:
include:
- env: COMPILER=g++-8 BUILD=Debug STANDARD=14
compiler: gcc
addons:
apt:
update: true
sources:
- sourceline: 'ppa:mhier/libboost-latest'
- ubuntu-toolchain-r-test
packages:
- g++-8
- boost1.67
- env: COMPILER=g++-8 BUILD=Release STANDARD=14
compiler: gcc
addons:
apt:
update: true
sources:
- sourceline: 'ppa:mhier/libboost-latest'
- ubuntu-toolchain-r-test
packages:
- g++-8
- boost1.67
before_script:
- wget https://cmake.org/files/v3.13/cmake-3.13.4-Linux-x86_64.sh
- sudo sh cmake-3.13.4-Linux-x86_64.sh -- --skip-license --prefix=/usr
script:
- cmake .
- cmake --build .
- cmake --build . --target package
cmake :
cmake_minimum_required(VERSION 3.10)
project(hcch VERSION 0.1.${VERSION_BUILD})
set(BOOST_ROOT /usr/include/boost/)
# For my linux
#set(BOOST_LIBRARYDIR /usr/local/lib)
# For travis-ci host
set(BOOST_LIBRARYDIR /usr/lib/x86_64-linux-gnu)
set(Boost_USE_STATIC_LIBS ON)
include_directories (${Boost_INCLUDE_DIRS})
link_directories (${Boost_LIBRARY_DIRS})
find_package(Boost 1.67 COMPONENTS program_options REQUIRED)
find_package(LLVM REQUIRED CONFIG)
configure_file (
"${PROJECT_SOURCE_DIR}/version.h.in"
"${PROJECT_BINARY_DIR}/version.h"
)
set(CMAKE_CXX_STANDARD 14)
add_executable(hcch hcch.cpp SourcesCreator.cpp SourcesCreator.h)
set_target_properties(hcch PROPERTIES
CXX_STANDARD 14
CXX_STANDARD_REQUIRED ON
COMPILE_OPTIONS -Wpedantic -Wall -Wextra
)
TARGET_LINK_LIBRARIES( hcch ${BOOST_LIBRARYDIR}/libboost_program_options.a )
Maybe static libraries are not installed from the ppa:mhier/libboost-latest?
Tell me how to fix it if someone came across.
This is my project https://github.com/angelskieglazki/hcch
regards, max
I can confirm that the libboost builds from ppa:mhier/libboost-latest do not currently build static libraries, only shared.
If it's essential that you must use a Boost version later than what is provided by libboost-all-dev then you will need to compile boost from source, although you will run the risk of timing out. Instructions for this can be found in Boost's best practice handbook.
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.