Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[boost] boost::dll/1.85.0: undefined reference to `dlopen' #23905

Open
ujos opened this issue May 7, 2024 · 2 comments
Open

[boost] boost::dll/1.85.0: undefined reference to `dlopen' #23905

ujos opened this issue May 7, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@ujos
Copy link
Contributor

ujos commented May 7, 2024

Description

I'm not sure if this issue has to be reported to Conan Center. Please create corresponding bug to the Boost team if needed.

The problem is if I use boost::dll from the conan repo, I get a link time error:

main.cpp:(.text.startup+0x8d): undefined reference to `dlclose'

The reason is that Conan recipe for Boost does not create a dll CMake target that depends on dl library.

To workaround the issue user must manually add dl library to their CMake target.

Package and Environment Details

  • Package Name/Version: boost/1.85.0
  • Operating System+version: CentOS Linux release 7.9.2009 (Core)
  • Compiler+version: GCC 7.3
  • Docker image: centos7.9.2009
  • Conan version: conan 1.58.0
  • Python version: Python 3.6.8

Conan profile

[settings]
os=Linux
os_build=Linux
arch=x86_64
arch_build=x86_64
compiler=gcc
compiler.version=7.3
compiler.libcxx=libstdc++

[options]

[build_requires]

[buildenv]
CC=/root/bin/GCC-7.3/bin/gcc
CXX=/root/bin/GCC-7.3/bin/g++

Steps to reproduce

  1. Install gcc 7.3
yum update
yum install texinfo gcc gcc-c++ wget bzip2 make

wget https://ftp.gnu.org/gnu/gcc/gcc-7.3.0/gcc-7.3.0.tar.gz
tar xvf gcc-7.3.0.tar.gz
cd gcc-7.3.0
./contrib/download_prerequisites
cd ..
mkdir obj
../gcc-7.3.0/configure --prefix=$HOME/bin/GCC-7.3 \
  --disable-multilib \
  --enable-languages=c,c++ \
  --disable-libsanitizer
make -j 8
  1. Create conanfile.txt
[requires]
boost/1.85.0

[generators]
CMakeDeps
CMakeToolchain
  1. Create CMakeLists.txt
cmake_minimum_required(VERSION 3.15)

project(test)

find_package(Boost REQUIRED filesystem)

add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(${PROJECT_NAME} Boost::boost)
target_link_libraries(${PROJECT_NAME} Boost::filesystem)
#target_link_libraries(${PROJECT_NAME} dl)
#target_link_libraries(${PROJECT_NAME} Boost::dll)
  1. Create main.cpp
#include <boost/dll.hpp>

void foo(char const* arg);

int main()
{
    auto handlerFactory = boost::dll::import_symbol<decltype(foo)>("shared", "foo", boost::dll::load_mode::append_decorations);
}
  1. Run conan and CMake
#!/usr/bin/env bash

target_directory=build

[ -e $target_directory ] || mkdir $target_directory
cd $target_directory

export CC=~/bin/GCC-7.3/bin/gcc
export CXX=~/bin/GCC-7.3/bin/g++
export PATH=$PATH:~/bin/GCC-7.3/bin
export LD_LIBRARY_PATH=~/bin/GCC-7.3/lib64/

#always rebuild b2 because it can be incompatible
conan install \
  --profile=default \
  -pr:b=default \
  --build=b2 \
  --build=missing \
  --settings build_type=Release \
  ../conanfile.txt

PARAMS=
PARAMS="${PARAMS} -DCMAKE_BUILD_TYPE=Release"
PARAMS="${PARAMS} -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake"
PARAMS="${PARAMS} -DCMAKE_POLICY_DEFAULT_CMP0091=NEW"

cmake -G "Unix Makefiles" $PARAMS $@ ../

cd ..
  1. Build the code
cd build
cmake --build .

Logs

Click to expand log
[root@a52f2ec72aa8 boost]# ./gcc_release.sh
Configuration (profile_host):
[settings]
arch=x86_64
arch_build=x86_64
build_type=Release
compiler=gcc
compiler.libcxx=libstdc++
compiler.version=7.3
os=Linux
os_build=Linux
[options]
[build_requires]
[env]
[buildenv]
CC=/root/bin/GCC-7.3/bin/gcc
CXX=/root/bin/GCC-7.3/bin/g++

Configuration (profile_build):
[settings]
arch=x86_64
arch_build=x86_64
compiler=gcc
compiler.libcxx=libstdc++
compiler.version=7.3
os=Linux
os_build=Linux
[options]
[build_requires]
[env]
[buildenv]
CC=/root/bin/GCC-7.3/bin/gcc
CXX=/root/bin/GCC-7.3/bin/g++

Version ranges solved
    Version range '>=1.2.11 <2' required by 'boost/1.85.0' resolved to 'zlib/1.3.1' in local cache

ERROR: No package matching 'b2' pattern found.
conanfile.txt: Installing package
Requirements
    boost/1.85.0 from 'conancenter' - Cache
    bzip2/1.0.8 from 'conancenter' - Cache
    libbacktrace/cci.20210118 from 'conancenter' - Cache
    zlib/1.3.1 from 'conancenter' - Cache
Packages
    boost/1.85.0:c9d4bf7e7a5a580844bcb62af62427d7898026ac - Cache
    bzip2/1.0.8:5c39baad2a4c92b4e96092a25e4899075a701d92 - Cache
    libbacktrace/cci.20210118:b09bec465fef58dc59f15f359cb57c2007336987 - Cache
    zlib/1.3.1:b09bec465fef58dc59f15f359cb57c2007336987 - Cache

Installing (downloading, building) binaries...
bzip2/1.0.8: Already installed!
libbacktrace/cci.20210118: Already installed!
zlib/1.3.1: Already installed!
boost/1.85.0: Already installed!
conanfile.txt: Generator 'CMakeToolchain' calling 'generate()'
conanfile.txt: Preset 'release' added to CMakePresets.json. Invoke it manually using 'cmake --preset release'
conanfile.txt: If your CMake version is not compatible with CMakePresets (<3.19) call cmake like: 'cmake <path> -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=/root/boost/build/conan_toolchain.cmake -DCMAKE_POLICY_DEFAULT_CMP0091=NEW -DCMAKE_BUILD_TYPE=Release'
conanfile.txt: Generator 'CMakeDeps' calling 'generate()'
conanfile.txt: Generator txt created conanbuildinfo.txt
conanfile.txt: Aggregating env generators
conanfile.txt: Generated conaninfo.txt
conanfile.txt: Generated graphinfo
-- Using Conan toolchain: /root/boost/build/conan_toolchain.cmake
-- The C compiler identification is GNU 7.3.0
-- The CXX compiler identification is GNU 7.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /root/bin/GCC-7.3/bin/gcc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /root/bin/GCC-7.3/bin/g++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Conan: Component target declared 'Boost::diagnostic_definitions'
-- Conan: Component target declared 'Boost::disable_autolinking'
-- Conan: Component target declared 'Boost::dynamic_linking'
-- Conan: Component target declared 'Boost::headers'
-- Conan: Component target declared 'Boost::boost'
-- Conan: Component target declared 'boost::_libboost'
-- Conan: Component target declared 'Boost::atomic'
-- Conan: Component target declared 'Boost::charconv'
-- Conan: Component target declared 'Boost::container'
-- Conan: Component target declared 'Boost::context'
-- Conan: Component target declared 'Boost::date_time'
-- Conan: Component target declared 'Boost::exception'
-- Conan: Component target declared 'Boost::math'
-- Conan: Component target declared 'Boost::math_c99'
-- Conan: Component target declared 'Boost::math_c99f'
-- Conan: Component target declared 'Boost::math_c99l'
-- Conan: Component target declared 'Boost::math_tr1'
-- Conan: Component target declared 'Boost::math_tr1f'
-- Conan: Component target declared 'Boost::math_tr1l'
-- Conan: Component target declared 'Boost::program_options'
-- Conan: Component target declared 'Boost::regex'
-- Conan: Component target declared 'Boost::serialization'
-- Conan: Component target declared 'Boost::stacktrace'
-- Conan: Component target declared 'Boost::stacktrace_addr2line'
-- Conan: Component target declared 'Boost::stacktrace_backtrace'
-- Conan: Component target declared 'Boost::stacktrace_basic'
-- Conan: Component target declared 'Boost::stacktrace_from_exception'
-- Conan: Component target declared 'Boost::stacktrace_noop'
-- Conan: Component target declared 'Boost::system'
-- Conan: Component target declared 'Boost::test'
-- Conan: Component target declared 'Boost::test_exec_monitor'
-- Conan: Component target declared 'Boost::timer'
-- Conan: Component target declared 'Boost::url'
-- Conan: Component target declared 'Boost::wserialization'
-- Conan: Component target declared 'Boost::chrono'
-- Conan: Component target declared 'Boost::coroutine'
-- Conan: Component target declared 'Boost::filesystem'
-- Conan: Component target declared 'Boost::json'
-- Conan: Component target declared 'Boost::nowide'
-- Conan: Component target declared 'Boost::prg_exec_monitor'
-- Conan: Component target declared 'Boost::random'
-- Conan: Component target declared 'Boost::thread'
-- Conan: Component target declared 'Boost::type_erasure'
-- Conan: Component target declared 'Boost::unit_test_framework'
-- Conan: Component target declared 'Boost::wave'
-- Conan: Component target declared 'Boost::contract'
-- Conan: Component target declared 'Boost::fiber'
-- Conan: Component target declared 'Boost::fiber_numa'
-- Conan: Component target declared 'Boost::graph'
-- Conan: Component target declared 'Boost::iostreams'
-- Conan: Component target declared 'Boost::locale'
-- Conan: Component target declared 'Boost::log'
-- Conan: Component target declared 'Boost::log_setup'
-- Conan: Target declared 'boost::boost'
-- Conan: Target declared 'BZip2::BZip2'
-- Conan: Including build module from '/root/.conan/data/bzip2/1.0.8/_/_/package/5c39baad2a4c92b4e96092a25e4899075a701d92/lib/cmake/conan-official-bzip2-variables.cmake'
-- Conan: Target declared 'ZLIB::ZLIB'
-- Conan: Target declared 'libbacktrace::libbacktrace'
-- Configuring done (0.2s)
-- Generating done (0.0s)
CMake Warning:
  Manually-specified variables were not used by the project:

    CMAKE_POLICY_DEFAULT_CMP0091


-- Build files have been written to: /root/boost/build

[root@a52f2ec72aa8 boost]#  
[root@a52f2ec72aa8 build]# make
[ 50%] Building CXX object CMakeFiles/test.dir/main.cpp.o
[100%] Linking CXX executable test
CMakeFiles/test.dir/main.cpp.o: In function `boost::detail::sp_counted_impl_pd<boost::dll::shared_library*, boost::detail::sp_ms_deleter<boost::dll::shared_library> >::~sp_counted_impl_pd()':
main.cpp:(.text._ZN5boost6detail18sp_counted_impl_pdIPNS_3dll14shared_libraryENS0_13sp_ms_deleterIS3_EEED2Ev[_ZN5boost6detail18sp_counted_impl_pdIPNS_3dll14shared_libraryENS0_13sp_ms_deleterIS3_EEED5Ev]+0x17): undefined reference to `dlclose'
CMakeFiles/test.dir/main.cpp.o: In function `boost::detail::sp_counted_impl_pd<boost::dll::shared_library*, boost::detail::sp_ms_deleter<boost::dll::shared_library> >::dispose()':
main.cpp:(.text._ZN5boost6detail18sp_counted_impl_pdIPNS_3dll14shared_libraryENS0_13sp_ms_deleterIS3_EEE7disposeEv[_ZN5boost6detail18sp_counted_impl_pdIPNS_3dll14shared_libraryENS0_13sp_ms_deleterIS3_EEE7disposeEv]+0x14): undefined reference to `dlclose'
CMakeFiles/test.dir/main.cpp.o: In function `boost::detail::sp_counted_impl_pd<boost::dll::shared_library*, boost::detail::sp_ms_deleter<boost::dll::shared_library> >::~sp_counted_impl_pd()':
main.cpp:(.text._ZN5boost6detail18sp_counted_impl_pdIPNS_3dll14shared_libraryENS0_13sp_ms_deleterIS3_EEED0Ev[_ZN5boost6detail18sp_counted_impl_pdIPNS_3dll14shared_libraryENS0_13sp_ms_deleterIS3_EEED5Ev]+0x1b): undefined reference to `dlclose'
CMakeFiles/test.dir/main.cpp.o: In function `boost::detail::sp_counted_base::release()':
main.cpp:(.text._ZN5boost6detail15sp_counted_base7releaseEv[_ZN5boost6detail15sp_counted_base7releaseEv]+0x33): undefined reference to `dlclose'
CMakeFiles/test.dir/main.cpp.o: In function `boost::dll::detail::report_error(boost::system::error_code const&, char const*)':
main.cpp:(.text._ZN5boost3dll6detail12report_errorERKNS_6system10error_codeEPKc[_ZN5boost3dll6detail12report_errorERKNS_6system10error_codeEPKc]+0xf): undefined reference to `dlerror'
CMakeFiles/test.dir/main.cpp.o: In function `main':
main.cpp:(.text.startup+0x8d): undefined reference to `dlclose'
main.cpp:(.text.startup+0xaf): undefined reference to `boost::filesystem::detail::path_algorithms::find_parent_path_size(boost::filesystem::path const&)'
main.cpp:(.text.startup+0xe2): undefined reference to `boost::filesystem::detail::path_algorithms::append_v3(boost::filesystem::path&, char const*, char const*)'
main.cpp:(.text.startup+0x148): undefined reference to `boost::filesystem::detail::path_algorithms::filename_v3(boost::filesystem::path const&)'
main.cpp:(.text.startup+0x1da): undefined reference to `dlopen'
main.cpp:(.text.startup+0x1ec): undefined reference to `dlerror'
main.cpp:(.text.startup+0x22c): undefined reference to `dlerror'
main.cpp:(.text.startup+0x2cc): undefined reference to `dlsym'
main.cpp:(.text.startup+0x330): undefined reference to `boost::filesystem::detail::path_algorithms::filename_v3(boost::filesystem::path const&)'
main.cpp:(.text.startup+0x33a): undefined reference to `boost::filesystem::detail::path_algorithms::find_parent_path_size(boost::filesystem::path const&)'
main.cpp:(.text.startup+0x484): undefined reference to `dlclose'
main.cpp:(.text.startup+0x4d9): undefined reference to `dlclose'
main.cpp:(.text.startup+0x56a): undefined reference to `boost::filesystem::detail::read_symlink(boost::filesystem::path const&, boost::system::error_code*)'
main.cpp:(.text.startup+0x591): undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
main.cpp:(.text.startup+0x5d7): undefined reference to `dlopen'
main.cpp:(.text.startup+0x5e9): undefined reference to `dlerror'
main.cpp:(.text.startup+0x62d): undefined reference to `boost::filesystem::detail::path_algorithms::find_parent_path_size(boost::filesystem::path const&)'
main.cpp:(.text.startup+0x69f): undefined reference to `boost::filesystem::detail::path_algorithms::append_v3(boost::filesystem::path&, char const*, char const*)'
main.cpp:(.text.startup+0x6e0): undefined reference to `boost::filesystem::detail::equivalent_v3(boost::filesystem::path const&, boost::filesystem::path const&, boost::system::error_code*)'
main.cpp:(.text.startup+0x83d): undefined reference to `boost::filesystem::detail::read_symlink(boost::filesystem::path const&, boost::system::error_code*)'
main.cpp:(.text.startup+0x8b5): undefined reference to `boost::filesystem::detail::equivalent_v3(boost::filesystem::path const&, boost::filesystem::path const&, boost::system::error_code*)'
main.cpp:(.text.startup+0x8f4): undefined reference to `dlerror'
main.cpp:(.text.startup+0x900): undefined reference to `dlopen'
main.cpp:(.text.startup+0xc1f): undefined reference to `dlclose'
collect2: error: ld returned 1 exit status
make[2]: *** [test] Error 1
make[1]: *** [CMakeFiles/test.dir/all] Error 2
make: *** [all] Error 2
@ujos ujos added the bug Something isn't working label May 7, 2024
@ujos ujos changed the title [boost] <dll>/<1.85.0>: undefined reference to `dlopen' [boost] boost::dll/1.85.0: undefined reference to `dlopen' May 7, 2024
@uilianries
Copy link
Member

@ujos Hello! Thank you for reporting. As we are using Ubuntu to generate Linux packages, we may result in different behavior, depending the distro. I'll try to reproduce your error, thank you for giving full details.

@uilianries uilianries self-assigned this May 7, 2024
@SpaceIm
Copy link
Contributor

SpaceIm commented May 8, 2024

Like other header-only libs, there is no dedicated target in FindBoost.cmake, it's part of Boost::headers. For dl, indeed it's a dependency on Linux: boostorg/dll#67

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants