Questions tagged [rpath]

rpath is an option used with the runtime linker (ld.so) to insert an RPATH header in either binaries or shared libraries. This header specifies the path search order for locating libraries.

rpath is an option used with the runtime linker on Unix and Linux (ld.so) to insert an RPATH header in either binaries or shared libraries. This header specifies the path search order for locating libraries.

The RPATH header is in the same format as the shell PATH variable, a list of directories separated by colons. There are some special tags that can be used which look like shell variables but which are really special commands to the shared library loader.

The most commonly used one is $ORIGIN which equals the current directory where the binary or shared library is located.

For instance, if I have ./x/bin/myprog and ./x/lib/libstuff.so.0 then I can make sure that myprog finds libstuff by setting its RPATH header to $ORIGIN/../lib. But if libstuff depends on libz then it will find that in /lib or /usr/lib. However, if I also set an RPATH header in libstuff.so.0 of $ORIGIN then it will first search ./x/lib for libz. Therefore I can copy libz to ./x/lib and also copy libstuff.so.0 to the same place and modify its RPATH.

If you are building and linking the software then you can control the RPATH header with the -rpath option. On linux you can also use a program named patchelf to fix it after the fact. The Solaris equivalent is elfedit. To check out current RPATH header, run readelf -d libtest.so on Linux or elfdump -d libtest.so

Setting RPATH is a polite thing to do for a self-contained app that you need to distribute to users since it helps to remove opportunities for finding incorrect versions of libraries.

219 questions
12
votes
1 answer

the shared library RPATH and the binary RPATH priority

if a shared library is linked to a binary, and the shared library also depends on other libs , what are the priorities (linker search order) of the RPATH of the shared library and the RPATH of the binary ? Could the RPATH of the binary override the…
user3450805
  • 661
  • 6
  • 16
11
votes
1 answer

how to change RPATH on OS X

I'm doing a simple installation from openkinect's website to use an xbox kinect. The problem is there is no OSX distribution and it is assumed homebrew will take care of the installation for you. On the final step of installation I came upon a…
Max
  • 2,072
  • 5
  • 26
  • 42
11
votes
1 answer

rpath of a shared object file

The rpath of an executable specifies one or more directories wherein to look for shared objects at runtime. My question is - do shared object files themselves also have statically-compiled rpaths? I recently received a runtime error when linking…
Siler
  • 8,976
  • 11
  • 64
  • 124
11
votes
4 answers

Setting RPATH order in QMake

I have a Linux Qt program. I'd like it to preferentially use the (dynamic) Qt libraries in the executable's directory if they exist, otherwise use the system's Qt libs. RPATH to the rescue. I add this line to the qmake's .pro file: QMAKE_LFLAGS …
Mike Blackwell
  • 487
  • 1
  • 6
  • 12
10
votes
2 answers

Why would runpath be ignored?

On CentOS 7.2, I've built an app with g++ 4.8.5 that can't run because it can't find a library that does exist in its runpath. I'm pretty sure it worked two weeks ago. What could cause this? $ ./app ./app: error while loading shared libraries:…
Qwertie
  • 16,354
  • 20
  • 105
  • 148
10
votes
2 answers

shared library locations for matlab mex files:

I am trying to write a matlab mex function which uses libhdf5; My Linux install provides libhdf5-1.8 shared libraries and headers. However, my version of Matlab, r2007b, provides a libhdf5.so from the 1.6 release. (Matlab .mat files bootstrap hdf5,…
shabbychef
  • 1,940
  • 3
  • 16
  • 28
9
votes
5 answers

How to compile OpenSSL with relative rpath

I have been trying to compile openssl 1.0.0g with the following rpath: $ORIGIN/../lib64 Everytime I readelf -d apps/openssl, I am getting results like the following depending on what escaping variation I…
Philippe A.
  • 2,885
  • 2
  • 28
  • 37
9
votes
1 answer

Cmake: How to set rpath to ${ORIGIN} with cmake

According to this SO question, Linux executable can't find shared library in same folder passing -Wl,-rpath,${ORIGIN} is the way to get a Linux executable to search for .sos in the same directory as the executable. We're using cmake, so I'm adding a…
dgnuff
  • 3,195
  • 2
  • 18
  • 32
9
votes
0 answers

CMake, RPATH, $ORIGIN and @loader_path

In my CMake project I build a bunch of libraries that are loaded at runtime as plugins. I therefore need to set various RPATHs so that these libraries can be found by the dynamic loading mechanism. I also need the whole thing to be relocatable,…
Ben Farmer
  • 2,387
  • 1
  • 25
  • 44
9
votes
1 answer

How to set dylib search path OSX

I have a project in Xcode where I set DYLD_FALLBACK_LIBRARY_PATH in the environment variables pane to set where my application should look for libraries to link to (which works well for my purposes) I am writing a CMakeLists.txt file to generate…
Tom
  • 1,956
  • 2
  • 18
  • 23
9
votes
2 answers

How to encode the executable location in a Linux rpath?

I have an executable that implicitly loads several .so libraries, all of them built by me. For deployment, or at least testing/debugging, I'd like to have them all in the same directory: my_executable libmylib1.so libmylib2.so To get the executable…
Ted Middleton
  • 6,859
  • 10
  • 51
  • 71
8
votes
1 answer

MobSF: Solve @rpath violation

We tested one of our iOS app with MobSF and the report highlighted that the binary has Runpath Search Path (@rpath) set. In certain cases an attacker can abuse this feature to run arbitrary executable for code execution and privilege escalation. I…
Markus
  • 81
  • 1
  • 2
8
votes
2 answers

How to use $ORIGIN and suid application?

I'm using python with setcap CAP_NET_RAW enabled. My python script imports a shared library which has $ORIGIN in its RPATH. Since my python is now a suid app, $ORIGIN is not evaluated and the library does not load correctly (this is due to a…
8
votes
1 answer

pkg-config: best practice for setting -rpath?

Are there any best practices to set -rpath or libtool's -R based on a pkg-config output? Do I have to resort to a sed trick?
nodakai
  • 7,773
  • 3
  • 30
  • 60
7
votes
3 answers

Library not loaded: @rpath/libtbb.dylib in Prophet / Python

I'm on a Mac X1, Monterey. I've installed prophet and run into this issue when trying to fit a model. RuntimeError: Error during optimization: console log output: dyld[90668]: Library not loaded: @rpath/libtbb.dylib Referenced from:…
cloud36
  • 1,026
  • 6
  • 21
  • 35
1
2
3
14 15