【问题标题】:Could not find the following Boost libraries: boost_fiber找不到以下 Boost 库: boost_fiber
【发布时间】:2019-03-29 22:38:58
【问题描述】:

我不熟悉提升。我想在 boost 中使用这个类,比如 boost::context::fiber 和 boost::context::continuation。所以,我下载了最新版本的 boost 1.68。通过官网instruction构建它。

首先,运行 bootstrap 并生成 b2 文件。

$ ./bootstrap.sh --with-libraries=all --prefix=/usr/local/boost_168_build

然后使用 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

我让一个 cmake 项目创建一个 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)

但是当我打开Boost_USE_STATIC_LIBS cmake 会报告:

/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)

关闭Boost_USE_STATIC_LIBS cmake 会报告:

/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)

最后,你知道我为什么能找到那个我真的很困惑吗???

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

但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

谁能告诉我我错过了哪里。谢谢

【问题讨论】:

    标签: c++ boost cmake coroutine


    【解决方案1】:

    你可以使用:

    b2 cxxflags="-std=c++14" --reconfigure --with-fiber

    编译 libboost_fiber.a

    【讨论】:

      【解决方案2】:

      fiber 是一个只有头文件的库,所以没有什么可以链接的,也不需要添加它作为一个组件来查找。

      已编译库的列表在文档中:https://www.boost.org/doc/libs/1_68_0/more/getting_started/unix-variants.html#header-only-libraries

      【讨论】:

      • 如您所见,我也认为光纤包含在其中,但为什么 cmake find_package( Boost REQUIRED COMPONENTS fiber) 找不到呢?
      • 因为component 部分会查找库。哪个失败了。根据定义,如果您要求具有光纤头的版本,它是可用的,您无需寻找它。
      • 我尝试编译项目boost_context并添加include_directories(${Boost_INCLUDE_DIRS})target_link_libraries(boost_context ${BOOST_LIBRARYDIR})编译输出为undefined reference to jump_fcontext'`collect2: error: ld returned 1 exit status
      • 谢谢我明白了,我错过了target_link_libraries(boost_context Boost::context)
      • 仅供参考,这在最初编写时可能是有道理的,但对于“现代”(即过去 10 年)CMake,这是非常糟糕的设计。没有理由不公开可以链接到的目标,因为没有需要链接的二进制库;目标暴露包括路径和类似的东西。
      猜你喜欢
      • 2019-06-20
      • 1970-01-01
      • 2013-09-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-26
      • 1970-01-01
      相关资源
      最近更新 更多