CMAKE_INSTALL_RPATH_USE_LINK_PATH has not effect with link directories outside /usr?


System: Ubuntu 18.04, x86_64
CMake version: 3.16.0
Compiler: GCC 7.5

I have the following interface target definition:

set(APP_CYBERRT_PREFIX "/usr/local/cyberRT")
if(EXISTS "${MY_ROOT}/install/cyberRT/bin/mainboard")
    set(APP_CYBERRT_PREFIX "${MY_ROOT}/install/cyberRT")
add_library(app_common_cyberrt INTERFACE)
add_library(app::common::cyberrt ALIAS app_common_cyberrt)
target_include_directories(app_common_cyberrt SYSTEM INTERFACE
                           ${APP_CYBERRT_PREFIX}/include /usr/local/fast-rtps/include)
target_link_directories(app_common_cyberrt INTERFACE
                        ${APP_CYBERRT_PREFIX}/lib /usr/local/fast-rtps/lib)
target_link_libraries(app_common_cyberrt INTERFACE
                      cyber_class_loader cyber_proto cyber_init cyber_node cyber_component
                      cyber_transport cyber_scheduler cyber_blocker _cyber_timer _cyber_time
                      cyber cyber_logger fastrtps fastcdr uuid)

Originally, the cyberRT is put at /usr/local/cyberRT, libraries stay under /usr/local/cyberRT/lib, with the option set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE), an installed binary gets the following entries in its RPATH:


And the executable can run without setting LD_LIBRARY_PATH.

Today I move the /usr/local/cyberRT package to some where like /my/root/install/cyberRT, the build is OK, executable inside build directory has also correct RPATH setting, it runs without problem.

But after installation, the installed executable has only /usr/local/fast-rtps/lib in its RPATH, not /my/root/install/cyberRT/lib, so the binary is not directly executable.

Now I have to explicitly apend those link directories to CMAKE_INSTALL_RPATH:


Is this intended bahavior? Or is it a bug?

It looks like this is cross-compilation of some kind? Usually one would use a prefix of /usr/local and a DESTDIR=/my/root I think. Such things probably work better with chroot or some other pivot mechanism to make the root appear as / (as it probably does once deployed).

No it is not cross-compiling.

Does anything (like some variable from cmake) can introduce such issue?

Ben Boeckel via CMake Discourse <>于2022年8月2日 周二19:25写道: