Cannot generate a safe runtime path

Hi,

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

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!

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

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?

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.

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

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

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.