# Cannot generate a safe runtime path

**URL:** https://discourse.cmake.org/t/cannot-generate-a-safe-runtime-path/4196
**Category:** Code
**Created:** [October 3, 2021, 2:19pm UTC](https://discourse.cmake.org/t/cannot-generate-a-safe-runtime-path/4196 "2021-10-03T14:19:06Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Leon0402](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/l/ccd318/32.png) [@Leon0402](https://discourse.cmake.org/u/Leon0402)
#### Post date: [October 3, 2021, 2:19pm UTC](https://discourse.cmake.org/t/cannot-generate-a-safe-runtime-path/4196/1 "2021-10-03T14:19:06Z")

</div>

Hi,

during generating I get multiple warnings “Cannot generate a safe runtime search path”, but I don’t quite understand it.

```auto
CMake Warning at build-analyze/_deps/cpr-src/cpr/CMakeLists.txt:3 (add_library):
  Cannot generate a safe runtime search path for target cpr because files in
  some directories may conflict with libraries in implicit directories:

    runtime library [libz.so.1] in /usr/lib may be hidden by files in:
      /home/leon/Projects/Beans/beans-server/build-analyze/lib

  Some of these libraries may not be found correctly.

```

The library is using curl, which might lead to conflicts? I would appreciate some help!

---

<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: [October 3, 2021, 4:10pm UTC](https://discourse.cmake.org/t/cannot-generate-a-safe-runtime-path/4196/2 "2021-10-03T16:10:56Z")

</div>

You have something linking to `/usr/lib/libz.so` (with soname `libz.so.1`), but other libraries it is linking to live in a directory (that `build-analyze/lib` one) which also has `libz.so.1`. CMake is saying that it cannot construct an rpath that will guarantee that `/usr/lib/libz.so.1` is picked up (that is, `build-analyze/lib/libz.so.1` will actually be used at runtime).

---

<div class="post-metadata">

### Author: ![Leon0402](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/l/ccd318/32.png) [@Leon0402](https://discourse.cmake.org/u/Leon0402)
#### Post date: [October 3, 2021, 4:28pm UTC](https://discourse.cmake.org/t/cannot-generate-a-safe-runtime-path/4196/3 "2021-10-03T16:28:36Z")

</div>

So cpr is linking against /usr/lib/libz.so and it’s also linking against library X in /some/path and /some/path happens to have also a libz.so?  
So cpr is confused here what it should take? (Or rather it will use the /some/path/libz.so instead of the usr/lib/libz.so)

Is that correct?

My next question: Does this mean I or the libraries I use have done something wrong? How can this happend and how to fix it?

---

<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: [October 3, 2021, 4:51pm UTC](https://discourse.cmake.org/t/cannot-generate-a-safe-runtime-path/4196/4 "2021-10-03T16:51:49Z")

</div>

For `libz.so`, it’s probably fine since the library has a stable ABI. However, I would recommend that your build be configured to agree on the same libraries to decrease the likelihood of odd linker-related issues at runtime.

---

<div class="post-metadata">

### Author: ![Leon0402](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/l/ccd318/32.png) [@Leon0402](https://discourse.cmake.org/u/Leon0402)
#### Post date: [October 8, 2021, 9:45pm UTC](https://discourse.cmake.org/t/cannot-generate-a-safe-runtime-path/4196/5 "2021-10-08T21:45:11Z")

</div>

The reason I (in general) got the problem in the first place is my cmake code:

```auto
if(NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)
    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR})
endif()
if(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
    set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
endif()
if(NOT CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
    set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
endif()

```

To put all libs and binaries in one folder to make the whole handling easier. Is this bad practise?

Apart from this I also figured out the library that built zlib

---

<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: [October 10, 2021, 8:51pm UTC](https://discourse.cmake.org/t/cannot-generate-a-safe-runtime-path/4196/6 "2021-10-10T20:51:16Z")

</div>

That block of code you have seems quite normal to me. In fact, I usually force it because the projects I work on are not intended to be vendored, so the only way to change the build tree locations is to update the install tree locations too.
