# RPATH via LINK\_OPTIONS or per default?

**URL:** <https://discourse.cmake.org/t/rpath-via-link-options-or-per-default/10677>\
**Category:** Code\
**Created:** [April 16, 2024, 3:49pm UTC](https://discourse.cmake.org/t/rpath-via-link-options-or-per-default/10677 "2024-04-16T15:49:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jwuttke](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@jwuttke](https://discourse.cmake.org/u/jwuttke)\
**Post date:** [April 16, 2024, 3:49pm UTC](https://discourse.cmake.org/t/rpath-via-link-options-or-per-default/10677/1 "2024-04-16T15:49:46Z")

</div>

We have CMake code like this:

```auto
    set(link_flags "--disable-new-dtags,-rpath,\$ORIGIN/../lib")
    set_target_properties(${executable_name} PROPERTIES LINK_OPTIONS ${link_flags})

```

Is this needed? The CMake docs indicate that RPATHS are set by default anyway??

Does our code influence only the built or also the installed library?

---

<div class="post-metadata">

**Author:** ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)\
**Post date:** [April 16, 2024, 10:18pm UTC](https://discourse.cmake.org/t/rpath-via-link-options-or-per-default/10677/2 "2024-04-16T22:18:40Z")

</div>

You shouldn’t need to add `-rpath` flags directly. CMake has direct support for specifying RPATH details, and it has separate controls for binaries in the build tree versus binaries you install. See the [`BUILD_RPATH`](https://cmake.org/cmake/help/latest/prop_tgt/BUILD_RPATH.html) and [`INSTALL_RPATH`](https://cmake.org/cmake/help/latest/prop_tgt/INSTALL_RPATH.html) target properties for details. You would normally use `CMAKE_BUILD_RPATH` and `CMAKE_INSTALL_RPATH` to set the details globally rather than on each individual target.

You may want to still keep the `--disable-new-dtags` flag though. That provides behavior that CMake doesn’t control.
