# CMAKE\_INSTALL\_RPATH\_USE\_LINK\_PATH has not effect with link directories outside /usr?

**URL:** <https://discourse.cmake.org/t/cmake-install-rpath-use-link-path-has-not-effect-with-link-directories-outside-usr/6158>\
**Category:** Code\
**Tags:** os:linux\
**Created:** [July 27, 2022, 11:55am UTC](https://discourse.cmake.org/t/cmake-install-rpath-use-link-path-has-not-effect-with-link-directories-outside-usr/6158 "2022-07-27T11:55:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zeroxia](https://discourse.cmake.org/user_avatar/discourse.cmake.org/zeroxia/32/2521_2.png) [@zeroxia](https://discourse.cmake.org/u/zeroxia)\
**Post date:** [July 27, 2022, 11:55am UTC](https://discourse.cmake.org/t/cmake-install-rpath-use-link-path-has-not-effect-with-link-directories-outside-usr/6158/1 "2022-07-27T11:55:52Z")

</div>

Hi,

System: Ubuntu 18.04, x86\_64  
CMake version: 3.16.0  
Compiler: GCC 7.5

I have the following interface target definition:

```auto
set(APP_CYBERRT_PREFIX "/usr/local/cyberRT")
if(EXISTS "${MY_ROOT}/install/cyberRT/bin/mainboard")
    set(APP_CYBERRT_PREFIX "${MY_ROOT}/install/cyberRT")
endif()
message(STATUS "app/common: APP_CYBERRT_PREFIX: ${APP_CYBERRT_PREFIX}")
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:

```auto
/usr/local/fast-rtps/lib
/usr/local/cyberRT/lib

```

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`:

```auto
list(APPEND CMAKE_INSTALL_RPATH $<TARGET_PROPERTY:app::common::cyberrt,INTERFACE_LINK_DIRECTORIES>)

```

Is this intended bahavior? Or is it a bug?  
Thanks.

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [August 2, 2022, 11:25am UTC](https://discourse.cmake.org/t/cmake-install-rpath-use-link-path-has-not-effect-with-link-directories-outside-usr/6158/2 "2022-08-02T11:25:14Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![zeroxia](https://discourse.cmake.org/user_avatar/discourse.cmake.org/zeroxia/32/2521_2.png) [@zeroxia](https://discourse.cmake.org/u/zeroxia)\
**Post date:** [August 2, 2022, 12:33pm UTC](https://discourse.cmake.org/t/cmake-install-rpath-use-link-path-has-not-effect-with-link-directories-outside-usr/6158/3 "2022-08-02T12:33:02Z")

</div>

No it is not cross-compiling.

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

Ben Boeckel via CMake Discourse \<[noreply@discourse.cmake.org](mailto:noreply@discourse.cmake.org)\>于2022年8月2日 周二19:25写道：
