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
313
votes
4 answers

I don't understand -Wl,-rpath -Wl,

For convenience I added the relevant manpages below. My (mis)understanding first: If I need to separate options with ,, that means that the second -Wl is not another option because it comes before , which means it is an argument to the -rpath…
Blub
  • 13,014
  • 18
  • 75
  • 102
111
votes
5 answers

Is there a programmatic way to inspect the current rpath on Linux?

I'm aware that it is possible to use readelf -d | grep RPATH to inspect a given binary from the shell, but is it possible to do this within a process? Something like (my completely made up system call): /* get a copy of current rpath into…
Justicle
  • 14,761
  • 17
  • 70
  • 94
99
votes
6 answers

How to stop MinGW and MSYS from mangling path names given at the command line

On Windows, I'm cross-compiling a program for ARM/Linux using CodeSourcery's cross-compiler suite. I use MinGW MSYS as my command interpreter, and very often it will mangle my paths and pathnames. For example, to build my program, I…
Ted Middleton
  • 6,859
  • 10
  • 51
  • 71
88
votes
15 answers

Install python 2.6 in CentOS

I have a shell that runs CentOS. For a project I'm doing, I need python 2.5+, but centOS is pretty dependent on 2.4. From what I've read, a number of things will break if you upgrade to 2.5. I want to install 2.5 separately from 2.4, but I'm not…
tehryan
  • 24,405
  • 11
  • 28
  • 17
54
votes
3 answers

Is there a Windows/MSVC equivalent to the -rpath linker flag?

On Linux/GCC I can use the -rpath flag to change an executables search path for shared libraries without tempering with environment variables. Can this also be accomplished on Windows? As far as I know, dlls are always searched in the executable's…
Shamoha
46
votes
4 answers

Why does ld need -rpath-link when linking an executable against a so that needs another so?

I'm just curious here. I have created a shared object: gcc -o liba.so -fPIC -shared liba.c And one more shared object, that links against the former one: gcc -o libb.so -fPIC -shared libb.c liba.so Now, when creating an executable that links…
Troels Folke
  • 917
  • 2
  • 9
  • 12
30
votes
6 answers

ld: Using -rpath,$ORIGIN inside a shared library (recursive)

I just made a basic example of using ld's -rpath option with $ORIGIN here (see 2nd response for a working version). I'm trying to create an example where main.run links to foo.so, which in turn links to bar.so, all using rpath and $ORIGIN. The…
Simon
  • 623
  • 1
  • 8
  • 13
30
votes
3 answers

correct usage of rpath (relative vs absolute)

When building a binary or library, specifying the rpath, i.e. -Wl,rpath, tells the linker where to find the required library at runtime of the binary. What is the UNIX philosphy regarding absolute and relative paths here? Is it better…
mattmilten
  • 6,242
  • 3
  • 35
  • 65
28
votes
3 answers

MacOSX: which dynamic libraries linked by binary?

I have not been able to figure out why my binary is not loading. It is a dylib loaded by MATLAB (MEX-file), and links to quite a few dylibs in different locations. MATLAB tells me it cannot load the MEX-file, but I cannot figure out which of its…
Cris Luengo
  • 55,762
  • 10
  • 62
  • 120
26
votes
4 answers

rpath=$ORIGIN not having desired effect?

I've got a binary "CeeloPartyServer" that needs to find libFoundation.so at runtime, on a FreeBSD machine. They're both in the same directory. I compile (on another platform, using a cross compiler) CeeloPartyServer using linker flag…
Nektarios
  • 10,173
  • 8
  • 63
  • 93
20
votes
1 answer

How to specify RPATH in a makefile?

I'm trying to specify rpath in my binary. My makefile looks like this- CC=gcc CFLAGS=-Wall LDFLAGS= -rpath='../libs/' main: main.c gcc -o main main.c clean: rm -f main main.o But when I query rpath using command readelf -a ./main |…
user837208
  • 2,487
  • 7
  • 37
  • 54
17
votes
2 answers

Building a simple (hello-world-esque) example of using ld's option -rpath with $ORIGIN

Note: Full working example now below. Original question follows: I'm having problems using ld's -rpath parameter with $ORIGIN. As I couldn't find a complete example, I thought I'd try to write one myself, so that I and others can use it later. Once…
Simon
  • 623
  • 1
  • 8
  • 13
17
votes
3 answers

How to get RPATH with $ORIGIN to work on Code::Blocks GCC?

I'm trying to link an RPATH containing the special string $ORIGIN into an executable built using GCC with the Code::Blocks IDE. I've specified -Wl,-R$ORIGIN in the linker options for the project, but the command line output to GCC is wrong…
kbluck
  • 11,530
  • 4
  • 25
  • 25
14
votes
1 answer

@rpath for a dynamic library embedded in a framework

I have an app, call it Animal.app. Inside its Contents/Frameworks folder is a framework, say Mammal.framework. And inside the Versions/A/Frameworks folder of the framework, I have dog.dylib. The install name of dog.dylib is @rpath/dog.dylib. For…
JWWalker
  • 22,385
  • 6
  • 55
  • 76
13
votes
1 answer

How to set multiple RPATH directories using CMake on MacOS

How do we set multiple RPATH directories on a target in CMake on MacOS? On Linux, we can just use a colon-separated list: set_target_properties(mytarget PROPERTIES INSTALL_RPATH "\$ORIGIN/../lib:\$ORIGIN/../thirdparty/lib" ) On MacOS, we…
wyer33
  • 6,060
  • 4
  • 23
  • 53
1
2 3
14 15