# "CMAKE\_INSTALL\_RPATH $ORIGIN" expands to empty

**URL:** https://discourse.cmake.org/t/cmake-install-rpath-origin-expands-to-empty/13876
**Category:** Usage
**Created:** [April 3, 2025, 1:36pm UTC](https://discourse.cmake.org/t/cmake-install-rpath-origin-expands-to-empty/13876 "2025-04-03T13:36:16Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![Taw\_Moto](https://discourse.cmake.org/user_avatar/discourse.cmake.org/taw_moto/32/5445_2.png) [@Taw\_Moto](https://discourse.cmake.org/u/Taw_Moto)
#### Post date: [April 3, 2025, 1:36pm UTC](https://discourse.cmake.org/t/cmake-install-rpath-origin-expands-to-empty/13876/1 "2025-04-03T13:36:16Z")

</div>

Hi, I have an `utils.cmake` file which is used by all my projects and some of the lines were

> set(CMAKE\_SHARED\_LINKER\_FLAGS “${CMAKE\_SHARED\_LINKER\_FLAGS} -Wl,-rpath,‘$ORIGIN’”)  
> set(CMAKE\_EXE\_LINKER\_FLAGS “${CMAKE\_EXE\_LINKER\_FLAGS} -Wl,-rpath,‘$ORIGIN’”)

Which was expanded to `-Wl,-rpath,'$ORIGIN'` and works perfectly.  
Now I am trying to modernize my code and, based on the Professional CMake book, I replaced it with:

> set(CMAKE\_INSTALL\_RPATH $ORIGIN)

But it seems that for some of the files it expands to `-Wl,-rpath,:::::::`, and I don’t understand why.

Here is a comparison of the flags before and after.

 ![image](https://discourse.cmake.org/uploads/default/original/2X/b/bc98df51a0174315856b0631ff30af40236067c5.png)

Should I do something special? Maybe put that line first or last, or add something? Should I put it for all the targets? Not sure how should I make it work

Thanks

---

<div class="post-metadata">

### Author: ![Angew](https://discourse.cmake.org/user_avatar/discourse.cmake.org/angew/32/229_2.png) [@Angew](https://discourse.cmake.org/u/Angew)
#### Post date: [April 3, 2025, 1:44pm UTC](https://discourse.cmake.org/t/cmake-install-rpath-origin-expands-to-empty/13876/2 "2025-04-03T13:44:44Z")

</div>

The variable which you’re using is used to pre-initialise the [property `INSTALL_RPATH`](https://cmake.org/cmake/help/latest/prop_tgt/INSTALL_RPATH.html) when a target is created, so if you want to use the variable, you must set it before you create the targets to which it should apply. Alternatively, you can set the property on the targets directly (after you create them).

Second, note that the variable affects _install_ RPATH; that is, RPATH that will be set by CMake as part of the install step (`make install` or equivalent). If you want to use the same RPATH also during the build, look into the [property `BUILD_WITH_INSTALL_RPATH`](https://cmake.org/cmake/help/latest/prop_tgt/BUILD_WITH_INSTALL_RPATH.html), which can similarly be pre-initialised with [variable `CMAKE_BUILD_WITH_INSTALL_RPATH`](https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_WITH_INSTALL_RPATH.html).

Alternatively, you can modify the build RPATH directly using [property `BUILD_RPATH`](https://cmake.org/cmake/help/latest/prop_tgt/BUILD_RPATH.html), which in turn can be pre-initialised using [variable `CMAKE_BUILD_RPATH`](https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_RPATH.html).

---

<div class="post-metadata">

### Author: ![Angew](https://discourse.cmake.org/user_avatar/discourse.cmake.org/angew/32/229_2.png) [@Angew](https://discourse.cmake.org/u/Angew)
#### Post date: [April 3, 2025, 2:53pm UTC](https://discourse.cmake.org/t/cmake-install-rpath-origin-expands-to-empty/13876/3 "2025-04-03T14:53:30Z")

</div>

Scanning CMake docs for an unrelated thing, I came upon [property `BUILD_RPATH_USE_ORIGIN`](https://cmake.org/cmake/help/latest/prop_tgt/BUILD_RPATH_USE_ORIGIN.html), which might also be relevant to your case.

---

<div class="post-metadata">

### Author: ![Taw\_Moto](https://discourse.cmake.org/user_avatar/discourse.cmake.org/taw_moto/32/5445_2.png) [@Taw\_Moto](https://discourse.cmake.org/u/Taw_Moto)
#### Post date: [April 3, 2025, 4:01pm UTC](https://discourse.cmake.org/t/cmake-install-rpath-origin-expands-to-empty/13876/4 "2025-04-03T16:01:50Z")

</div>

@Angew thanks a lot for your great help, it seems that I needed this line added `set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)`

Meanwhile I found that CMake 3.15 (which I use) has a problem with escaping RPATH, so I am not sure if I should escape the `$` or not, like it’s recommended here: [https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling](https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling)

Now I am trying to make it work on macos also  
this `set(CMAKE_INSTALL_RPATH "@loader_path")`, although it expands to `-Wl,-rpath,"\$ORIGIN"`, the executable cannot find the libraries.  
`Library not loaded: @rpath/libfile.dylib`

---

<div class="post-metadata">

### Author: ![emaschino](https://discourse.cmake.org/user_avatar/discourse.cmake.org/emaschino/32/6126_2.png) [@emaschino](https://discourse.cmake.org/u/emaschino)
#### Post date: [August 8, 2025, 5:24pm UTC](https://discourse.cmake.org/t/cmake-install-rpath-origin-expands-to-empty/13876/5 "2025-08-08T17:24:56Z")

</div>

Hi,

Well, I’m hitting the same issue than @Taw_Moto.

No matter how I try to set `INSTALL_RPATH` to `$ORIGIN` with the `CMAKE_INSTALL_RPATH` command (tried various syntax such as `$ORIGIN`, `"\$ORIGIN"`, `"${ORIGIN}"`, `\\\$ORIGIN`, `'$ORIGIN'`, …), I’m always getting `:::::::` (the number of colons depends on the used syntax) as `RUNPATH` entry in the target’s binary file. It’s noteworthy that the target’s cmake\_install.cmake script correctly mirrors the used syntax `$ORIGIN`, `"\$ORIGIN"`, `"${ORIGIN}"`, `\\\$ORIGIN`, `'$ORIGIN'`, … as `RPATH` in the `file(RPATH_CHECK` statement. Since it differs from the `RUNPATH :::::::` entry in the binary file, the latter get deleted on install.

I’ve double-checked: the target is definitely created **after** the call to `CMAKE_INSTALL_RPATH` command.

By contrast, as outlined by @Taw_Moto, setting `RPATH` to `$ORIGIN` using the `CMAKE_EXE_LINKER_FLAGS` command yields to a correct `RUNPATH $ORIGIN` entry in the target’s binary file, matching the `RPATH` value expected by the `file(RPATH_CHECK` statement in the cmake\_install.cmake script and the executable thus installs flawlessly.

What am I missing here? This is with CMake 3.26.5 as provided with Red Hat Enterprise Linux 8. I’m stuck with this version because of IT requirements.

Thanks.

---

<div class="post-metadata">

### Author: ![vito.gamberini](https://discourse.cmake.org/user_avatar/discourse.cmake.org/vito.gamberini/32/4376_2.png) [@vito.gamberini](https://discourse.cmake.org/u/vito.gamberini)
#### Post date: [August 9, 2025, 12:53pm UTC](https://discourse.cmake.org/t/cmake-install-rpath-origin-expands-to-empty/13876/6 "2025-08-09T12:53:35Z")

</div>

RPATHs are rewritten on install, the colons are placeholder characters. Perform the install and the RPATHs will be rewritten into the binaries.

---

<div class="post-metadata">

### Author: ![emaschino](https://discourse.cmake.org/user_avatar/discourse.cmake.org/emaschino/32/6126_2.png) [@emaschino](https://discourse.cmake.org/u/emaschino)
#### Post date: [August 15, 2025, 8:35pm UTC](https://discourse.cmake.org/t/cmake-install-rpath-origin-expands-to-empty/13876/7 "2025-08-15T20:35:03Z")

</div>

Well, I wish I could 🙂 As I said, because the generated target’s binary file has `:::::::` as a placeholder for `RUNPATH` on one hand but the `file(RPATH_CHECK` statement in cmake\_install.cmake expects `$ORIGIN` on the other hand, the target’s binary file is deleted rather than installed.

---

<div class="post-metadata">

### Author: ![emaschino](https://discourse.cmake.org/user_avatar/discourse.cmake.org/emaschino/32/6126_2.png) [@emaschino](https://discourse.cmake.org/u/emaschino)
#### Post date: [September 24, 2025, 4:17pm UTC](https://discourse.cmake.org/t/cmake-install-rpath-origin-expands-to-empty/13876/8 "2025-09-24T16:17:11Z")

</div>

Just tried with recent CMake 4.1.0: still the same problem. At the moment, the only solution that works for me is to totally disable run time path information with `set(CMAKE_SKIP_RPATH TRUE)` and manually set them with `set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath,\$ORIGIN")`. This not only allows to install the produced binary (as it successfully passes the `file(RPATH_CHECK` statement in cmake\_install.cmake this way) but also allows the binary to run flawlessly by installing its runtime dependencies alongside the install directory.

---

<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: [February 20, 2026, 2:56am UTC](https://discourse.cmake.org/t/cmake-install-rpath-origin-expands-to-empty/13876/9 "2026-02-20T02:56:35Z")

</div>

Can you please provide an example project which showcases the problem so that someone else can reproduce the issue?

---

<div class="post-metadata">

### Author: ![emaschino](https://discourse.cmake.org/user_avatar/discourse.cmake.org/emaschino/32/6126_2.png) [@emaschino](https://discourse.cmake.org/u/emaschino)
#### Post date: [April 30, 2026, 2:23pm UTC](https://discourse.cmake.org/t/cmake-install-rpath-origin-expands-to-empty/13876/10 "2026-04-30T14:23:56Z")

</div>

[SharedLibraryExample.tbz](https://discourse.cmake.org/uploads/short-url/ggpvKJcn2djRvbPHtYSUqnMGY0r.tbz) (1.1 KB)

Please find the attached SharedLibraryExample project with `CMAKE_INSTALL_RPATH` simply set to `$ORIGIN`.

To configure:

```bash
cmake -B build_x86_64/Debug -DCMAKE_CXX_FLAGS="-fPIC" -DCMAKE_INSTALL_PREFIX=build_x86_64/Debug/install -DCMAKE_BUILD_TYPE=Debug

```

To build:

```bash
cmake --build build_x86_64/Debug

```

Quick checks give:

```bash
$ readelf -d build_x86_64/Debug/libShared.so | grep PATH
0x000000000000001d (RUNPATH) Library runpath: [:::::::]

```

```bash
$ readelf -d build_x86_64/Debug/Example | grep PATH
0x000000000000001d (RUNPATH) Library runpath: [/home/<user>/SharedLibraryExample/build_x86_64/Debug:]

```

`file(RPATH_CHECK` statements in cmake\_install.cmake read as:

```cmake
file(RPATH_CHECK
     FILE "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/lib64/libShared.so"
     RPATH "\$ORIGIN")

```

```cmake
file(RPATH_CHECK
     FILE "$ENV{DESTDIR}/home/<user>/SharedLibraryExample/build_x86_64/Debug/Example"
     RPATH "\$ORIGIN")

```

Trying to perform install will thus fail, as expected and currently set `RUNPATH` differ and `RPATH_CHECK` ends up deleting the Example binary:

```bash
$ cmake --build build_x86_64/Debug -t install
[50%] Built target Shared
[100%] Built target Example
Install the project...
-- Install configuration: "Debug"
-- Installing: /home/<user>/SharedLibraryExample/build_x86_64/Debug/install/lib64/libShared.so
-- Set non-toolchain portion of runtime path of "/home/<user>/SharedLibraryExample/build_x86_64/Debug/install/lib64/libShared.so" to "$ORIGIN"
-- Installing: /home/<user>/SharedLibraryExample/build_x86_64/Debug/install/include/SharedLibrary/SharedLibrary.h
CMake Error at cmake_install.cmake:87 (file):
file INSTALL cannot find
"/home/<user>/SharedLibraryExample/build_x86_64/Debug/Example": No such file
or directory.

gmake: *** [Makefile:100 : install] Error 1

```

As explained in my previous post, skipping `RUNPATH` info and passing them as link options is actually the only solution giving me something working. To this end, in the CMakeLists.txt file provided in the SharedLibraryExample project:

- comment out ln. 7: `#set(CMAKE_INSTALL_RPATH $ORIGIN)`
- uncomment ln. 10: `set(CMAKE_SKIP_RPATH TRUE)`
- uncomment ln. 48: `target_link_options(Example PRIVATE "LINKER:-rpath,$ORIGIN")`

Re-run configure:

```bash
cmake -B build_x86_64/Debug -DCMAKE_CXX_FLAGS="-fPIC" -DCMAKE_INSTALL_PREFIX=build_x86_64/Debug/install -DCMAKE_BUILD_TYPE=Debug

```

Build and install at once:

```bash
$ cmake --build build_x86_64/Debug -t install
[25%] Building CXX object CMakeFiles/Shared.dir/src/SharedLibrary.cpp.o
[50%] Linking CXX shared library libShared.so
[50%] Built target Shared
[75%] Building CXX object CMakeFiles/Example.dir/src/main.cpp.o
[100%] Linking CXX executable Example
[100%] Built target Example
Install the project...
-- Install configuration: "Debug"
-- Installing: /home/<user>/SharedLibraryExample/build_x86_64/Debug/install/lib64/libShared.so
-- Installing: /home/<user>/SharedLibraryExample/build_x86_64/Debug/install/include/SharedLibrary/SharedLibrary.h

```

No problem this time.

Checks give:

```auto
$ readelf -d build_x86_64/Debug/libShared.so | grep PATH

```

```auto
$ readelf -d build_x86_64/Debug/Example | grep PATH
0x000000000000001d (RUNPATH) Library runpath: [$ORIGIN]

```

cmake\_install.cmake is empty of any `RPATH_CHECK` statement. And of course, binary is working fine 🙂  
`$ ./build_x86_64/Debug/Example`  
`Hello!`

Hope this helps.
