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

libspdlogd.so.1.14 => not found, can't find the way to link spdlog with an rpath #3174

Open
olivier-lemaire opened this issue Sep 10, 2024 · 2 comments

Comments

@olivier-lemaire
Copy link

olivier-lemaire commented Sep 10, 2024

Hi there,
I'm trying to build a small toy project. I want to build spdlog as a shared library, link it relative to my executable using a rpath.
Before installation, the executable is correctly linked to spdlog

$ ldd build/exe_1 
        linux-vdso.so.1 (0x00007f05d9733000)
        libx2_daq_configuration.so => /home/lemaire/code/cxx/xemis/tests/rpath_and_output_directory/build/src/lib/x2_daq_configuration/libx2_daq_configuration.so (0x00007f05d96af000)
        libx2_timestamp_generator.so => /home/lemaire/code/cxx/xemis/tests/rpath_and_output_directory/build/src/lib/x2_time_stamp_generator/libx2_timestamp_generator.so (0x00007f05d968b000)
        libx2_mapping.so => /home/lemaire/code/cxx/xemis/tests/rpath_and_output_directory/build/src/lib/x2_mapping_generator/libx2_mapping.so (0x00007f05d9623000)
        libspdlogd.so.1.14 => /home/lemaire/code/cxx/xemis/tests/rpath_and_output_directory/build/_deps/spdlog-build/libspdlogd.so.1.14 (0x00007f05d9200000)
        libfmtd.so.11 => /home/lemaire/code/cxx/xemis/tests/rpath_and_output_directory/build/_deps/fmt-build/libfmtd.so.11 (0x00007f05d95c1000)
        libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f05d8e00000)
        libm.so.6 => /lib64/libm.so.6 (0x00007f05d94b4000)
        libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f05d9486000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f05d8c0f000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f05d9735000)

after install the executable can no longer find spdlog

$ ldd install/bin/exe_1 
        linux-vdso.so.1 (0x00007f78f3f34000)
        libx2_daq_configuration.so => /home/lemaire/code/cxx/xemis/tests/rpath_and_output_directory/install/bin/../lib/libx2_daq_configuration.so (0x00007f78f3eb0000)
        libx2_timestamp_generator.so => /home/lemaire/code/cxx/xemis/tests/rpath_and_output_directory/install/bin/../lib/libx2_timestamp_generator.so (0x00007f78f3e8c000)
        libx2_mapping.so => /home/lemaire/code/cxx/xemis/tests/rpath_and_output_directory/install/bin/../lib/libx2_mapping.so (0x00007f78f3e24000)
        libspdlogd.so.1.14 => not found
        libfmtd.so.11 => /home/lemaire/code/cxx/xemis/tests/rpath_and_output_directory/install/bin/../lib64/libfmtd.so.11 (0x00007f78f3d99000)
        libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f78f3a00000)
        libm.so.6 => /lib64/libm.so.6 (0x00007f78f3cb5000)
        libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f78f3c87000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f78f380f000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f78f3f36000)

Below is my CmakeLists

cmake_minimum_required(VERSION 3.28)
project(rpath_and_output_directory)

set(CMAKE_CXX_STANDARD 17)

# -----------------------------------------------------------------------
# bibliothèque partagée
# -----------------------------------------------------------------------
option(BUILD_SHARED_LIBS "Build using shared libraries" ON)

# ------------------------------------------------------------------------------
# fmt
# ------------------------------------------------------------------------------
message(STATUS "-> getting fmt from github")
include(FetchContent)
FetchContent_Declare(
  fmt
  GIT_REPOSITORY https://github.com/fmtlib/fmt.git
  GIT_TAG 0c9fce2ffefecfdce794e1859584e25877b7b592 # 11.0.2
  GIT_PROGRESS ON
  )

FetchContent_MakeAvailable(fmt)

# ------------------------------------------------------------------------------
# spdlog
# ------------------------------------------------------------------------------
message(STATUS "-> getting spdlog from github")
set(SPDLOG_FMT_EXTERNAL ON)
set(SPDLOG_BUILD_SHARED ON)
FetchContent_Declare(
  spdlog
  GIT_REPOSITORY https://github.com/gabime/spdlog.git
  GIT_TAG 27cb4c76708608465c413f6d0e6b8d99a4d84302
  GIT_PROGRESS ON
  )

FetchContent_MakeAvailable(spdlog)

# ------------------------------------------------------------------------------
# installation
# ------------------------------------------------------------------------------
# où est-ce que le projet est installé
set(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/install")

# Configurer le rpath pour pointer vers le répertoire des bibliothèques dynamiques
set(CMAKE_BUILD_RPATH_USE_ORIGIN ON)
set(CMAKE_INSTALL_RPATH "$ORIGIN/../lib:$ORIGIN/../lib64:$ORIGIN")

# use, i.e. don't skip the full RPATH for the build tree
set(CMAKE_SKIP_BUILD_RPATH FALSE)

# when building, don't use the install RPATH already
# (but later on when installing)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)


# add the automatically determined parts of the RPATH
# which point to directories outside the build tree to the install RPATH
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

# ------------------------------------------------------------------------------
# les bibliothèques internes
# ------------------------------------------------------------------------------

add_subdirectory("${CMAKE_SOURCE_DIR}/src/lib/x2_daq_configuration")
add_subdirectory("${CMAKE_SOURCE_DIR}/src/lib/x2_time_stamp_generator")
add_subdirectory("${CMAKE_SOURCE_DIR}/src/lib/x2_mapping_generator")

# ------------------------------------------------------------------------------
# les éxecutables
# ------------------------------------------------------------------------------
add_executable(exe_1 exe_1.cxx)
target_link_libraries(exe_1 PRIVATE
  x2_daq_configuration
  x2_timestamp_generator
  x2_mapping
  fmt::fmt
  spdlog::spdlog
  )

add_executable(exe_2 exe_2.cxx)
target_link_libraries(exe_2 PRIVATE
  x2_daq_configuration
  x2_timestamp_generator
  x2_mapping
  fmt::fmt
  spdlog::spdlog
  )

# ------------------------------------------------------------------------------
# installation
# ------------------------------------------------------------------------------
install(TARGETS exe_1 DESTINATION bin)
install(TARGETS exe_2 DESTINATION bin)
install(TARGETS x2_timestamp_generator x2_mapping x2_daq_configuration DESTINATION lib)

Why is spdlog not correctly linked after installation, while all other libraries are?

Thank you for your time and consideration.

Olivier

@tt4g
Copy link
Contributor

tt4g commented Sep 10, 2024

If you want to install imported spdlog as part of your project, define SPDLOG_INSTALL=ON.

option(SPDLOG_INSTALL "Generate the install target" ${SPDLOG_MASTER_PROJECT})

The spdlog install command is not defined because SPDLOG_INSTALL=OFF is the default (if spdlog not top level).

spdlog/CMakeLists.txt

Lines 47 to 57 in 271f0f3

# ---------------------------------------------------------------------------------------
# Set SPDLOG_MASTER_PROJECT to ON if we are building spdlog
# ---------------------------------------------------------------------------------------
# Check if spdlog is being used directly or via add_subdirectory, but allow overriding
if(NOT DEFINED SPDLOG_MASTER_PROJECT)
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(SPDLOG_MASTER_PROJECT ON)
else()
set(SPDLOG_MASTER_PROJECT OFF)
endif()
endif()

@olivier-lemaire
Copy link
Author

Hi tt4g
thank you very much for your message, it helped a lot. Everything is now working as expected.
Have a very good day.
Olivier

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants