1

I'm trying to configure a project using the boost library from conan-center on linux. To test my problem in a smaller environment, I've created a project which you can test.

https://github.com/resqsx/conan-boost

I'm testing on

  • ubuntu 18.04
  • conan 1.24.0
  • boost 1.72.0

My conafile looks like this:

[requires]
boost/1.72.0

[options]
boost:shared=True

[generators]
cmake

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

And the 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)

My build process seems ok according to the outcome:

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

But when I check my shared libraries I already see the issue.

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)

The libraries filesystem and regex cannot be found.

What is wrong with my configuration?

Resq
  • 161
  • 1
  • 8
  • You probably don't need ``include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)``, as this should be automatically managed by the ``conan_cmake_run()``. – drodri Apr 14 '20 at 15:35
  • Quick question: what happens if you use static linkage? Does it link and run properly? – drodri Apr 14 '20 at 15:35
  • When I set Boost::shared=False it just compiles the used functions inside my code and as part of linking looks ok. – Resq Apr 15 '20 at 05:56
  • I am interested in the runtime too. So statically linking you can link and run your app successfully. With shared linking, does it throw runtime errors because not finding boost regex and filesystem shared libs? Also why ``libboost_filesystem.so.1.72.0 => not found`` appears twice? Is there something special in your toolchain, or just the standard gnu linker? – drodri Apr 15 '20 at 12:25

1 Answers1

1

I think the problem lies in the transitive dependencies of some libraries like libboost_log to libboost_filesystem.

This article helped me understanding How to set RPATH and RUNPATH with GCC/LD?

As far as I can say, since Ubuntu 18.04. the linker uses RUNPATH instead of RPATH. But the problem with RUNPATH is that the loader doesn't use it to search for transitive dependencies.

One solution is to set LD_LIBRARY_PATH before calling your application. Which I don't like.

Another way is to tell cmake to install with RPATH like so

set(CMAKE_EXE_LINKER_FLAGS "-Wl,--disable-new-dtags")

And than set the wanted lib path to "." or whatever you want.

set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath -Wl,.")

You can see the difference using readelf -d When everything is ok, it should look like this. Using 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]

Otherwise when configured with RUNPATH it looks like this

  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]
Resq
  • 161
  • 1
  • 8