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
5
votes
2 answers

libtool install preserves temporary rpath of executable

I am modifying a project that is very similar to examples provided by the Automake/libtool documentation. Excerpts: Top-leve configure.ac: LT_INIT Top-level Makefile.am: ACLOCAL_AMFLAGS = -I m4 SUBDIRS = src doc ./src Makefile.am: lib_LTLIBRARIES…
user19087
  • 1,899
  • 1
  • 16
  • 21
5
votes
2 answers

libraries which exist in a binary's elf RUNPATH are not being used?

I have custom built gcc-4.7.2 in my environment. The system gcc is gcc-4.3.4. I have patched the RUNPATH for all my custom gcc's binaries and shared libraries using patchelf --set-rpath However, when I run ldd on my 4.7.2 cc1 it picks up the system…
Steve Lorimer
  • 27,059
  • 17
  • 118
  • 213
5
votes
1 answer

AIX 5.3 (ld-xlc) equivalent option Linux (ld-gcc) -rpath

My compiler:xlc version 10.1 Environment: AIX5.3 Linker: ld When i work on Linux , with gcc (4.4.1) i use the following option -Wl,-rpath (-Wl for the linker options) it adds a directory to the runtime library search path. What's the equivalent…
Nadir SOUALEM
  • 3,451
  • 2
  • 23
  • 30
4
votes
3 answers

How to avoid the removal of the RPATH during CMake install step?

I am working on a C++ project using CMake where I build an executable foo that uses a shared library libbar (that is being added via ExternalProject_add). The executable build/src/foo in the build directory works perfectly fine. However, if I run…
user157765
  • 85
  • 8
4
votes
1 answer

Using -rpath and $ORIGIN with libtool-based projects?

I am trying to incorporate a libtool-based package into a project of my own, perhaps in a non-standard way. Here is my goal: Build external project: ./configure --prefix=$HOME/blah --etcetera && make && make install Build my own project which…
Tom
  • 10,689
  • 4
  • 41
  • 50
4
votes
4 answers

rpmbuild check-rpath reports error that path is not absolute, incorrectly

I've been building RPMs using CMake & CPack 3.13.4 on OEL7 for several months without issue. My CMake configuration contained these lines: SET(CMAKE_SKIP_BUILD_RPATH FALSE) SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) SET(CMAKE_INSTALL_RPATH…
Obiphil
  • 361
  • 1
  • 6
  • 17
4
votes
1 answer

Cannot find shared libraries even -rpath is set correctly

I am building a third party program which is using libraries from a directory which is not set in /etc/ld.so.conf - therefore I link the program with the -rpath option. Running objdump -x bin/GetHistPrices | grep -i path to check if -rpath is set…
Peter VARGA
  • 4,780
  • 3
  • 39
  • 75
4
votes
0 answers

Properly manage shared libraries with CMake

I'm trying to link a cmake build with two shared libraries, linking occurs but RPATH is pointing to an absolute path of one of the two libraries while readelf output is incorrect for the other. What I did is the following: add_library(foo SHARED…
Jack
  • 131,802
  • 30
  • 241
  • 343
4
votes
1 answer

Rust and loader paths (@rpath, @loader_path) on OS X

I'm trying to solve a problem with foreign library loading with Rust. Inputs: I have an executable rtest and a dylib libcpp2rs.dylib. The library is linked to the executable through FFI: #[link(name="cpp2rs")] extern { ... } My build.rs file (I'm…
4
votes
1 answer

Dynamic libraries passed to the linker as absolute paths being loaded by relative path?

I'm attempting to build and run a project I'm working on. I go ahead and build and everything's wonderful, no errors of any sort. Then when I try to run an executable, I get an error message that some of the dynamic library dependencies could not be…
alexgolec
  • 26,898
  • 33
  • 107
  • 159
4
votes
0 answers

macdeployqt ERROR: Cannot resolve rpath "QtGui.framework/Versions/5/QtGui (compatibility version 5.5.0, current version 5.5.0)"

I use qmake to compile my Qt Application project on my MacBook. It need a dylib called libcore.dylib, and I put it into dir $$OUT_PWD/../libs. for compile, I add this code in .pro file win32:CONFIG(release, debug|release): LIBS +=…
sjchao
  • 41
  • 4
4
votes
1 answer

Use CMAKE_MACOSX_RPATH to link a library outside build tree

This issue is MacOS X specific. I would like to link a library lib_xxx that sits outside my build tree at some arbitrary location. It will be at the same location in all systems. By default CMake would add the dependency as follows…
Oleg Zhylin
  • 1,290
  • 12
  • 18
4
votes
1 answer

Prevent autotools from setting rpath when compiling my program

I'm working on an example autotools project which builds a shared library and a program. The program should link to the shared library. But when I build the program libtool will set the rpath like this: RPATH=/usr/local/lib which I don't…
StMartin81
  • 41
  • 4
4
votes
1 answer

Shipping GNU/Linux Firefox plugin with shared libraries (for installation with no root access)

The application is a Firefox plugin (loaded from $HOME/.mozilla/plugins), so wrapper script that sets LD_LIBRARY_PATH is not an easy option. RPATH, as far as I know, cannot refer to $HOME and can be only absolue path. Firefox tries to dlopen it's…
Vi.
  • 37,014
  • 18
  • 93
  • 148
4
votes
2 answers

Escaping in rpm spec file

I am trying to set the rpath in my spec file with a statement like export LDFLAGS="-Wl-rpath=$ORIGIN/../lib" But I can't correctly escape "$ORIGIN". I need the command to gcc to contain the string "$ORIGIN", not expand it anywhere along the line. I…
pythonic metaphor
  • 10,296
  • 18
  • 68
  • 110