# What is the right way to use RPATH on UNIX?

**URL:** https://discourse.cmake.org/t/what-is-the-right-way-to-use-rpath-on-unix/13335
**Category:** Code
**Created:** [January 6, 2025, 9:44pm UTC](https://discourse.cmake.org/t/what-is-the-right-way-to-use-rpath-on-unix/13335 "2025-01-06T21:44:46Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![AnthonyD973](https://discourse.cmake.org/user_avatar/discourse.cmake.org/anthonyd973/32/3130_2.png) [@AnthonyD973](https://discourse.cmake.org/u/AnthonyD973)
#### Post date: [January 7, 2025, 11:27pm UTC](https://discourse.cmake.org/t/what-is-the-right-way-to-use-rpath-on-unix/13335/2 "2025-01-07T23:27:15Z")

</div>

[Here](https://github.com/adentinger/CMakeBestPractices/blob/b150317500d7886a2998ebaf8561250ea9d1085f/prj2/lib2/CMakeLists.txt#L152) is an example of mine, with explanatory comments. Disclaimer: haven’t used this in production at this time, but it seems to be working fine on Linux and MacOS.

Note that there is also `RUNPATH`, which is used only if `RPATH` and `LD_LIBRARY_PATH` don’t contain the sought library. According to [here](https://discourse.cmake.org/t/setting-rpath-and-not-runpath-for-executable/10011/3) it’s up to the linker to choose between using `RPATH` vs `RUNPATH`.

---

_[View the full topic](https://discourse.cmake.org/t/what-is-the-right-way-to-use-rpath-on-unix/13335)._
