1

I would like to automatically add the path of libraries at link time to RPATH. After reading a bit I thought CMAKE_INSTALL_RPATH_USE_LINK_PATH should do the job. Unfortunatly, the following MWE does not do the job:

cmake_minimum_required(VERSION 3.9)

cmake_policy(SET CMP0060 NEW)
set(CMAKE_SKIP_BUILD_RPATH  FALSE)
# set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
# set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

find_package(Boost COMPONENTS serialization REQUIRED)
# Setting CMAKE_INSTALL_RPATH explicitly works
# set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH};${Boost_LIBRARY_DIRS}")

add_executable(app main.cxx)

target_include_directories( app
    PUBLIC ${Boost_INCLUDE_DIR})

target_link_libraries( app
    PUBLIC Boost::serialization)

install(TARGETS app DESTINATION bin)

The output of readelf -d install/bin/app for the example above shows the dependencies but no RPATH:

0x0000000000000001 (NEEDED)             Shared library: [libboost_serialization.so.1.65.1]
0x0000000000000001 (NEEDED)             Shared library: [libstdc++.so.6]
0x0000000000000001 (NEEDED)             Shared library: [libm.so.6]
0x0000000000000001 (NEEDED)             Shared library: [libgcc_s.so.1]
0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]

The commented lines is some stuff that I tried so far. Setting CMAKE_INSTALL_RPATH explicitly works. But setting CMAKE_INSTALL_RPATH_USE_LINK_PATH seems to have no effect. This is the case for both binaries, the build and the installed one.

Do I misunderstand what CMAKE_INSTALL_RPATH_USE_LINK_PATH is doing or can someone spot the mistake? CMake 3.13, CentOS 7

hansgans
  • 307
  • 4
  • 12

1 Answers1

2

I still do not understand exactly whats going on but here and here I found the hint that the environment variable LIBRARY_PATH (probably also CPATH and CPLUS_INCLUDE_PATH) influences which directories are added to RPATH if CMAKE_INSTALL_RPATH_USE_LINK_PATH is set. Those variables were set in my case by easybuild. My guess is directories provided in LIBRARY_PATH at compile/link time are not added to RPATH. Unsetting LIBRARY_PATH solved my problem.

hansgans
  • 307
  • 4
  • 12