Linux 找不到Conan boost共享库

Linux 找不到Conan boost共享库,linux,boost,cmake,shared-libraries,conan,Linux,Boost,Cmake,Shared Libraries,Conan,我正在尝试使用linux上柯南中心的boost库配置一个项目。 为了在较小的环境中测试我的问题,我创建了一个项目,您可以对其进行测试 我正在测试 ubuntu 18.04 柯南1.24.0 boost 1.72.0 我的conafile如下所示: [requires] boost/1.72.0 [options] boost:shared=True [generators] cmake [imports] bin, *.dll -> ./bin lib, *.dylib* -&

我正在尝试使用linux上柯南中心的boost库配置一个项目。 为了在较小的环境中测试我的问题,我创建了一个项目,您可以对其进行测试

我正在测试

  • ubuntu 18.04
  • 柯南1.24.0
  • boost 1.72.0
我的conafile如下所示:

[requires]
boost/1.72.0

[options]
boost:shared=True

[generators]
cmake

[imports]
bin, *.dll -> ./bin
lib, *.dylib* -> ./bin
lib, *.so* -> ./bin
和CMake:

cmake_minimum_required (VERSION 3.12.0)

project(spielwiese)

# Load Conan
include(${CMAKE_SOURCE_DIR}/conan.cmake)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)

conan_cmake_run(CONANFILE conanfile.txt
BASIC_SETUP CMAKE_TARGETS BUILD missing)

add_executable(spielwiese spielwiese.cpp)

target_link_libraries(spielwiese CONAN_PKG::boost)

根据结果,我的构建过程似乎还可以:

Configuration:
[settings]
arch=x86_64
arch_build=x86_64
build_type=Release
compiler=gcc
compiler.libcxx=libstdc++11
compiler.version=7
os=Linux
os_build=Linux
[options]
[build_requires]
[env]

conanfile.txt: Installing package
Requirements
    boost/1.72.0 from 'conan-center' - Cache
    bzip2/1.0.8 from 'conan-center' - Cache
    zlib/1.2.11 from 'conan-center' - Cache
Packages
    boost/1.72.0:5b61a950a8e504865808bd4e284db10c833b020f - Cache
    bzip2/1.0.8:b27e2b40bcb70be2e7d6f0e0c6e43e35c530f8d3 - Cache
    zlib/1.2.11:d50a0d523d98c15bb147b18fa7d203887c38be8b - Cache

Installing (downloading, building) binaries...
bzip2/1.0.8: Already installed!
zlib/1.2.11: Already installed!
boost/1.72.0: Already installed!
boost/1.72.0: LIBRARIES: ['boost_wave', 'boost_container', 'boost_contract', 'boost_exception', 'boost_graph', 'boost_iostreams', 'boost_locale', 'boost_log', 'boost_program_options', 'boost_random', 'boost_regex', 'boost_serialization', 'boost_wserialization', 'boost_coroutine', 'boost_fiber', 'boost_context', 'boost_timer', 'boost_thread', 'boost_chrono', 'boost_date_time', 'boost_atomic', 'boost_filesystem', 'boost_system', 'boost_type_erasure', 'boost_log_setup', 'boost_math_c99', 'boost_math_c99f', 'boost_math_c99l', 'boost_math_tr1', 'boost_math_tr1f', 'boost_math_tr1l', 'boost_stacktrace_addr2line', 'boost_stacktrace_backtrace', 'boost_stacktrace_basic', 'boost_stacktrace_noop', 'boost_unit_test_framework']
boost/1.72.0: Package folder: /media/DATA/conan_data_linux/boost/1.72.0/_/_/package/5b61a950a8e504865808bd4e284db10c833b020f
conanfile.txt: Generator cmake created conanbuildinfo.cmake
conanfile.txt: Generator txt created conanbuildinfo.txt
conanfile.txt: Generated conaninfo.txt
conanfile.txt: Generated graphinfo
conanfile.txt imports(): Copied 36 '.0' files
conanfile.txt imports(): Copied 36 '.72' files
conanfile.txt imports(): Copied 36 '.1' files
conanfile.txt imports(): Copied 36 '.so' files
-- Conan: Automatic detection of conan settings from cmake
-- Conan: Settings= -s;build_type=Release;-s;compiler=gcc;-s;compiler.version=7;-s;compiler.libcxx=libstdc++11
-- Conan: checking conan executable
-- Conan: Found program /home/.local/bin/conan
-- Conan: Version found Conan version 1.24.0

-- Conan executing: /home/.local/bin/conan install /home/work/tim_spielwiese/conanfile.txt -s build_type=Release -s compiler=gcc -s compiler.version=7 -s compiler.libcxx=libstdc++11 -g=cmake --build=missing
Configuration:
[settings]
arch=x86_64
arch_build=x86_64
build_type=Release
compiler=gcc
compiler.libcxx=libstdc++11
compiler.version=7
os=Linux
os_build=Linux
[options]
[build_requires]
[env]

conanfile.txt: Installing package
Requirements
    boost/1.72.0 from 'conan-center' - Cache
    bzip2/1.0.8 from 'conan-center' - Cache
    zlib/1.2.11 from 'conan-center' - Cache
Packages
    boost/1.72.0:5b61a950a8e504865808bd4e284db10c833b020f - Cache
    bzip2/1.0.8:b27e2b40bcb70be2e7d6f0e0c6e43e35c530f8d3 - Cache
    zlib/1.2.11:d50a0d523d98c15bb147b18fa7d203887c38be8b - Cache

Installing (downloading, building) binaries...
bzip2/1.0.8: Already installed!
zlib/1.2.11: Already installed!
boost/1.72.0: Already installed!
boost/1.72.0: LIBRARIES: ['boost_wave', 'boost_container', 'boost_contract', 'boost_exception', 'boost_graph', 'boost_iostreams', 'boost_locale', 'boost_log', 'boost_program_options', 'boost_random', 'boost_regex', 'boost_serialization', 'boost_wserialization', 'boost_coroutine', 'boost_fiber', 'boost_context', 'boost_timer', 'boost_thread', 'boost_chrono', 'boost_date_time', 'boost_atomic', 'boost_filesystem', 'boost_system', 'boost_type_erasure', 'boost_log_setup', 'boost_math_c99', 'boost_math_c99f', 'boost_math_c99l', 'boost_math_tr1', 'boost_math_tr1f', 'boost_math_tr1l', 'boost_stacktrace_addr2line', 'boost_stacktrace_backtrace', 'boost_stacktrace_basic', 'boost_stacktrace_noop', 'boost_unit_test_framework']
boost/1.72.0: Package folder: /media/DATA/conan_data_linux/boost/1.72.0/_/_/package/5b61a950a8e504865808bd4e284db10c833b020f
conanfile.txt: Generator cmake created conanbuildinfo.cmake
conanfile.txt: Generator txt created conanbuildinfo.txt
conanfile.txt: Generated conaninfo.txt
conanfile.txt: Generated graphinfo
conanfile.txt imports(): Copied 36 '.1' files
conanfile.txt imports(): Copied 36 '.0' files
conanfile.txt imports(): Copied 36 '.so' files
conanfile.txt imports(): Copied 36 '.72' files
-- Conan: Loading conanbuildinfo.cmake
-- Conan: Adjusting output directories
-- Conan: Using cmake targets configuration
-- Library boost_wave found /media/DATA/conan_data_linux/boost/1.72.0/_/_/package/5b61a950a8e504865808bd4e284db10c833b020f/lib/libboost_wave.so
-- Library boost_container found /media/DATA/conan_data_linux/boost/1.72.0/_/_/package/5b61a950a8e504865808bd4e284db10c833b020f/lib/libboost_container.so
-- Library boost_contract found /media/DATA/conan_data_linux/boost/1.72.0/_/_/package/5b61a950a8e504865808bd4e284db10c833b020f/lib/libboost_contract.so
-- Library boost_exception found /media/DATA/conan_data_linux/boost/1.72.0/_/_/package/5b61a950a8e504865808bd4e284db10c833b020f/lib/libboost_exception.a
-- Library boost_graph found /media/DATA/conan_data_linux/boost/1.72.0/_/_/package/5b61a950a8e504865808bd4e284db10c833b020f/lib/libboost_graph.so
-- Library boost_iostreams found /media/DATA/conan_data_linux/boost/1.72.0/_/_/package/5b61a950a8e504865808bd4e284db10c833b020f/lib/libboost_iostreams.so
-- Library boost_locale found /media/DATA/conan_data_linux/boost/1.72.0/_/_/package/5b61a950a8e504865808bd4e284db10c833b020f/lib/libboost_locale.so
-- Library boost_log found /media/DATA/conan_data_linux/boost/1.72.0/_/_/package/5b61a950a8e504865808bd4e284db10c833b020f/lib/libboost_log.so
-- Library boost_program_options found /media/DATA/conan_data_linux/boost/1.72.0/_/_/package/5b61a950a8e504865808bd4e284db10c833b020f/lib/libboost_program_options.so
-- Library boost_random found /media/DATA/conan_data_linux/boost/1.72.0/_/_/package/5b61a950a8e504865808bd4e284db10c833b020f/lib/libboost_random.so
-- Library boost_regex found /media/DATA/conan_data_linux/boost/1.72.0/_/_/package/5b61a950a8e504865808bd4e284db10c833b020f/lib/libboost_regex.so
-- Library boost_serialization found /media/DATA/conan_data_linux/boost/1.72.0/_/_/package/5b61a950a8e504865808bd4e284db10c833b020f/lib/libboost_serialization.so
-- Library boost_wserialization found /media/DATA/conan_data_linux/boost/1.72.0/_/_/package/5b61a950a8e504865808bd4e284db10c833b020f/lib/libboost_wserialization.so
-- Library boost_coroutine found /media/DATA/conan_data_linux/boost/1.72.0/_/_/package/5b61a950a8e504865808bd4e284db10c833b020f/lib/libboost_coroutine.so
-- Library boost_fiber found /media/DATA/conan_data_linux/boost/1.72.0/_/_/package/5b61a950a8e504865808bd4e284db10c833b020f/lib/libboost_fiber.so
-- Library boost_context found /media/DATA/conan_data_linux/boost/1.72.0/_/_/package/5b61a950a8e504865808bd4e284db10c833b020f/lib/libboost_context.so
-- Library boost_timer found /media/DATA/conan_data_linux/boost/1.72.0/_/_/package/5b61a950a8e504865808bd4e284db10c833b020f/lib/libboost_timer.so
-- Library boost_thread found /media/DATA/conan_data_linux/boost/1.72.0/_/_/package/5b61a950a8e504865808bd4e284db10c833b020f/lib/libboost_thread.so
-- Library boost_chrono found /media/DATA/conan_data_linux/boost/1.72.0/_/_/package/5b61a950a8e504865808bd4e284db10c833b020f/lib/libboost_chrono.so
-- Library boost_date_time found /media/DATA/conan_data_linux/boost/1.72.0/_/_/package/5b61a950a8e504865808bd4e284db10c833b020f/lib/libboost_date_time.so
-- Library boost_atomic found /media/DATA/conan_data_linux/boost/1.72.0/_/_/package/5b61a950a8e504865808bd4e284db10c833b020f/lib/libboost_atomic.so
-- Library boost_filesystem found /media/DATA/conan_data_linux/boost/1.72.0/_/_/package/5b61a950a8e504865808bd4e284db10c833b020f/lib/libboost_filesystem.so
-- Library boost_system found /media/DATA/conan_data_linux/boost/1.72.0/_/_/package/5b61a950a8e504865808bd4e284db10c833b020f/lib/libboost_system.so
-- Library boost_type_erasure found /media/DATA/conan_data_linux/boost/1.72.0/_/_/package/5b61a950a8e504865808bd4e284db10c833b020f/lib/libboost_type_erasure.so
-- Library boost_log_setup found /media/DATA/conan_data_linux/boost/1.72.0/_/_/package/5b61a950a8e504865808bd4e284db10c833b020f/lib/libboost_log_setup.so
-- Library boost_math_c99 found /media/DATA/conan_data_linux/boost/1.72.0/_/_/package/5b61a950a8e504865808bd4e284db10c833b020f/lib/libboost_math_c99.so
-- Library boost_math_c99f found /media/DATA/conan_data_linux/boost/1.72.0/_/_/package/5b61a950a8e504865808bd4e284db10c833b020f/lib/libboost_math_c99f.so
-- Library boost_math_c99l found /media/DATA/conan_data_linux/boost/1.72.0/_/_/package/5b61a950a8e504865808bd4e284db10c833b020f/lib/libboost_math_c99l.so
-- Library boost_math_tr1 found /media/DATA/conan_data_linux/boost/1.72.0/_/_/package/5b61a950a8e504865808bd4e284db10c833b020f/lib/libboost_math_tr1.so
-- Library boost_math_tr1f found /media/DATA/conan_data_linux/boost/1.72.0/_/_/package/5b61a950a8e504865808bd4e284db10c833b020f/lib/libboost_math_tr1f.so
-- Library boost_math_tr1l found /media/DATA/conan_data_linux/boost/1.72.0/_/_/package/5b61a950a8e504865808bd4e284db10c833b020f/lib/libboost_math_tr1l.so
-- Library boost_stacktrace_addr2line found /media/DATA/conan_data_linux/boost/1.72.0/_/_/package/5b61a950a8e504865808bd4e284db10c833b020f/lib/libboost_stacktrace_addr2line.so
-- Library boost_stacktrace_backtrace found /media/DATA/conan_data_linux/boost/1.72.0/_/_/package/5b61a950a8e504865808bd4e284db10c833b020f/lib/libboost_stacktrace_backtrace.so
-- Library boost_stacktrace_basic found /media/DATA/conan_data_linux/boost/1.72.0/_/_/package/5b61a950a8e504865808bd4e284db10c833b020f/lib/libboost_stacktrace_basic.so
-- Library boost_stacktrace_noop found /media/DATA/conan_data_linux/boost/1.72.0/_/_/package/5b61a950a8e504865808bd4e284db10c833b020f/lib/libboost_stacktrace_noop.so
-- Library boost_unit_test_framework found /media/DATA/conan_data_linux/boost/1.72.0/_/_/package/5b61a950a8e504865808bd4e284db10c833b020f/lib/libboost_unit_test_framework.so
-- Library z found /media/DATA/conan_data_linux/zlib/1.2.11/_/_/package/d50a0d523d98c15bb147b18fa7d203887c38be8b/lib/libz.a
-- Library bz2 found /media/DATA/conan_data_linux/bzip2/1.0.8/_/_/package/b27e2b40bcb70be2e7d6f0e0c6e43e35c530f8d3/lib/libbz2.a
-- Conan: Adjusting default RPATHs Conan policies
-- Conan: Adjusting language standard
-- Current conanbuildinfo.cmake directory: /home/work/tim_spielwiese/build
-- Conan: Compiler GCC>=5, checking major version 7
-- Conan: Checking correct version: 7
-- Configuring done
-- Generating done
-- Build files have been written to: /home/work/tim_spielwiese/build
[2/2] Linking CXX executable bin/spielwiese
但是当我检查我的共享库时,我已经看到了这个问题

ldd ./build/bin/spielwiese 

    linux-vdso.so.1 (0x00007fff27d49000)
    libboost_log.so.1.72.0 => /media/DATA/conan_data_linux/boost/1.72.0/_/_/package/5b61a950a8e504865808bd4e284db10c833b020f/lib/libboost_log.so.1.72.0 (0x00007fe57101e000)
    libboost_thread.so.1.72.0 => /media/DATA/conan_data_linux/boost/1.72.0/_/_/package/5b61a950a8e504865808bd4e284db10c833b020f/lib/libboost_thread.so.1.72.0 (0x00007fe570dfa000)
    libboost_log_setup.so.1.72.0 => /media/DATA/conan_data_linux/boost/1.72.0/_/_/package/5b61a950a8e504865808bd4e284db10c833b020f/lib/libboost_log_setup.so.1.72.0 (0x00007fe570b4c000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fe57092d000)
    libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fe5705a4000)
    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fe57038c000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fe56ff9b000)
    libboost_filesystem.so.1.72.0 => not found
    librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fe56fd93000)
    /lib64/ld-linux-x86-64.so.2 (0x00007fe571532000)
    libboost_regex.so.1.72.0 => not found
    libboost_filesystem.so.1.72.0 => not found
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fe56f9f5000)

找不到文件系统库和正则表达式库


我的配置有什么问题?

我认为问题在于一些库(如libboost\u log到libboost\u文件系统)的可传递依赖关系

这篇文章帮助我理解

据我所知,自从Ubuntu 18.04以来。链接器使用运行路径而不是RPATH。 但是运行路径的问题是加载程序不使用它来搜索可传递的依赖项

一种解决方案是在调用应用程序之前设置LD_LIBRARY_路径。我不喜欢

另一种方法是让cmake像这样使用RPATH安装

set(CMAKE_EXE_LINKER_FLAGS "-Wl,--disable-new-dtags")
然后将想要的库路径设置为
或任何您想要的

set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath -Wl,.")
您可以使用
readelf-d
当一切正常时,它应该是这样的。使用RPATH

 Tag             Type                   Name/value
 0x0000000000000001 (NEEDED)             Shared library: [libboost_log.so.1.72.0]
 0x0000000000000001 (NEEDED)             Shared library: [libboost_thread.so.1.72.0]
 0x0000000000000001 (NEEDED)             Shared library: [libboost_log_setup.so.1.72.0]
 0x0000000000000001 (NEEDED)             Shared library: [libpthread.so.0]
 0x0000000000000001 (NEEDED)             Shared library: [libstdc++.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libgcc_s.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
 0x000000000000000f (RPATH)              Library rpath: [.:/media/DATA/conan_data_linux/boost/1.72.0/_/_/package/5b61a950a8e504865808bd4e284db10c833b020f/lib]
否则,当使用运行路径进行配置时,它将如下所示

  Tag        Type                         Name/Value
 0x0000000000000001 (NEEDED)             Shared library: [libboost_log.so.1.72.0]
 0x0000000000000001 (NEEDED)             Shared library: [libboost_thread.so.1.72.0]
 0x0000000000000001 (NEEDED)             Shared library: [libboost_log_setup.so.1.72.0]
 0x0000000000000001 (NEEDED)             Shared library: [libpthread.so.0]
 0x0000000000000001 (NEEDED)             Shared library: [libstdc++.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libgcc_s.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
 0x000000000000001d (RUNPATH)            Library runpath: [.:/media/DATA/conan_data_linux/boost/1.72.0/_/_/package/5b61a950a8e504865808bd4e284db10c833b020f/lib]

您可能不需要
include(${CMAKE\u BINARY\u DIR}/conanbuildinfo.CMAKE)
,因为这应该由
conan\u CMAKE\u run()
自动管理。快速问题:如果使用静态链接会发生什么?它链接并正常运行吗?当我设置Boost::shared=False时,它只编译代码中使用的函数,作为链接的一部分,它看起来还可以。我也对运行时感兴趣。因此,静态链接可以成功链接并运行应用程序。对于共享链接,它是否会因为找不到boost regex和文件系统共享lib而引发运行时错误?还有为什么
libboost\u filesystem.so.1.72.0=>notfound
会出现两次?你的工具链中有什么特别的东西吗,或者只是标准的gnu链接器?