Issue
As per the document, which says:
CMAKE_BUILD_RPATH¶ New in version 3.8.
Semicolon-separated list specifying runtime path (RPATH) entries to add to binaries linked in the build tree (for platforms that support it). The entries will not be used for binaries in the install tree. See also the CMAKE_INSTALL_RPATH variable.
This is used to initialize the BUILD_RPATH target property for all targets.
As per the document, which says:
CMAKE_INSTALL_RPATH¶ The rpath to use for installed targets.
A semicolon-separated list specifying the rpath to use in installed targets (for platforms that support it). This is used to initialize the target property INSTALL_RPATH for all targets.
How to understand the differences between CMAKE_BUILD_RPATH
and CMAKE_INSTALL_RPATH
in the right way?
A small and clear example is welcome.
Solution
When building binaries one can set the RPATH to support library path resolution at runtime.
There are two scenarios for which to build binaries. The first an obvious scenario is to debug a program. This means the binary will be built and (normally) executed from the location it has been built. Details can vary but in general it is under the cmake build directory.
This means if you build for example two libraries in your project libA
and libB
. libA
dynamically linking libB
. This means both libraries are located somewhere in the binary path. To run a binary in the build path with runtime dependency resolution you CAN specify the CMAKE_BUILD_PATH or the recommended target property BUILD_RPATH with an absolute or relative value.
lib | location | rpath |
---|---|---|
libA | /home/user/my_tool/build/liba | ./../libb/ or /home/user/my_tool/build/libb |
libB | /home/user/my_tool/build/libb |
Then you can smoothly run your binary from the build path and everything should work without modifying the LD_LIBRARY_PATH system environment variable for dependency lookup.
The same applies to the RPATH if the binary gets installed (cmake install). In this case the value of the RPATH could be different. To accommodate this there are these two CMake features to distinguish between the scenarios.
lib | location | rpath |
---|---|---|
libA | /usr/lib/my_tool | . or /usr/bin/my_tool |
libB | /usr/lib/my_tool |
Answered By - Johnny_xy Answer Checked By - Senaida (WPSolving Volunteer)