... | ... | @@ -29,7 +29,7 @@ the same library installed, e.g. `/opt/kde3/lib/libkdecore.so` and |
|
|
|
|
|
For the first case it would work if the user would set `LD_LIBRARY_PATH`
|
|
|
accordingly:
|
|
|
``` bash
|
|
|
```shell
|
|
|
export LD_LIBRARY_PATH=$HOME/lib:$LD_LIBRARY_PATH
|
|
|
```
|
|
|
|
... | ... | @@ -49,8 +49,8 @@ install name of `/usr/lib/libSystem.B.dylib` as given by `otool -D`. |
|
|
When linked into "foo", "foo" has a dependency on
|
|
|
`/usr/lib/libSystem.B.dylib`. This dependency can be seen with `otool -L
|
|
|
foo`. For relocatable binaries, `@executable_path`, `@loader_path` and
|
|
|
`@rpath` are available to use. In the "foo" example, @executable_path and
|
|
|
@loader_path are substituted for the location of "foo". @rpath is
|
|
|
`@rpath` are available to use. In the "foo" example, `@executable_path` and
|
|
|
`@loader_path` are substituted for the location of "foo". `@rpath` is
|
|
|
substituted with the RPATHs in "foo" to locate dependent dylibs. Thus
|
|
|
the RPATH mechanism comes into play. The linker will search for `@rpath`/
|
|
|
dependencies in the following order:
|
... | ... | @@ -106,7 +106,7 @@ libraries in the build tree. When installing, it will clear the RPATH of |
|
|
these targets so they are installed with an empty RPATH. On Mac OS X,
|
|
|
with `MACOSX_RPATH` on, the install names for dylibs will include
|
|
|
`@rpath/` prefix. This is equivalent to:
|
|
|
``` cmake
|
|
|
```cmake
|
|
|
# use, i.e. don't skip the full RPATH for the build tree
|
|
|
set(CMAKE_SKIP_BUILD_RPATH FALSE)
|
|
|
|
... | ... | @@ -133,7 +133,7 @@ directories). |
|
|
In many cases you will want to make sure that the required libraries are
|
|
|
always found independent from `LD_LIBRARY_PATH` and the install
|
|
|
location. Then you can use these settings:
|
|
|
``` cmake
|
|
|
```cmake
|
|
|
# use, i.e. don't skip the full RPATH for the build tree
|
|
|
set(CMAKE_SKIP_BUILD_RPATH FALSE)
|
|
|
|
... | ... | @@ -175,7 +175,7 @@ directory yourself to the install RPATH by setting `CMAKE_INSTALL_RPATH` |
|
|
accordingly.
|
|
|
|
|
|
If your library is created and installed like this:
|
|
|
``` cmake
|
|
|
```cmake
|
|
|
add_library(bar SHARED bar.c blub.c)
|
|
|
install(TARGETS bar DESTINATION lib)
|
|
|
```
|
... | ... | @@ -205,7 +205,7 @@ without the `CMAKE_` prefix. |
|
|
|
|
|
Q) I have created an executable like this:
|
|
|
|
|
|
``` cmake
|
|
|
```cmake
|
|
|
add_executable(ImageCompleter ${AppSources})
|
|
|
target_link_libraries(ImageCompleter ${LibrariesAlwaysUsed})
|
|
|
|
... | ... | @@ -221,7 +221,7 @@ when I run the one that is copied by `make install` I get something like: |
|
|
What do I do?
|
|
|
|
|
|
A) Add to your `CMakeLists.txt`:
|
|
|
``` cmake
|
|
|
```cmake
|
|
|
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
|
|
|
```
|
|
|
|
... | ... | @@ -271,7 +271,7 @@ CMake RPATH-related variables. |
|
|
|
|
|
On Linux, one may use
|
|
|
|
|
|
``` bash
|
|
|
```shell
|
|
|
objdump -x executable_or_lib.so|grep RPATH
|
|
|
```
|
|
|
|
... | ... | |