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
3
votes
1 answer

automake and custom rpath

I have to ship a third-party library with an application. Because I don't want to set LD_LIBRARY_PATH by hand or require any wrapper script I want automake to set a custom rpath. Unfortunately libtool has its own -rpath option and adding…
scai
  • 20,297
  • 4
  • 56
  • 72
2
votes
1 answer

linux linker/loader search order

This question is related to the way libraries are looked up during compilation and dynamic linking. Consider this small project: project liba a.hpp a.cpp libb b.hpp b.cpp main.cpp a.hpp: int AAA(); a.cpp: #include int AAA() { …
mabr
  • 21
  • 2
2
votes
1 answer

cmake: how to set rpath in a shared library with only target_link_directories (without target_link_libraries)?

The goal of my project is as follows: From my main executable, I want to load a library (libfoo.so) that loads a second library (libbar.so). I want to not specify either relative or absolute paths in any filename arguments that I pass to dlopen:…
StoneThrow
  • 5,314
  • 4
  • 44
  • 86
2
votes
0 answers

Binary with RPATH not finding transitive dependencies if one of them has RUNPATH

I've been reading for a while about how the dynamic linker/loader works, RPATH vs RUNPATH, direct vs transitive dependencies, etc. My understanding so far is that if a binary has RPATH (not RUNPATH), then its RPATH is what the dynamic loader uses to…
user1011113
  • 1,114
  • 8
  • 27
2
votes
1 answer

Bundling FFMPEG using CMAKE and RPATH

As the title explains, I am trying to bundle FFMPEG with my executable application. However, I can't seem to figure out the runtime loading of the FFMPEG shared libraries. I'm not sure what is incorrect: RPATH/RUNPATH of main project and FFMPEG…
Cole
  • 43
  • 4
2
votes
1 answer

Rpath/Runpath handle with dependent shared libraries in CMAKE

I will put you in context: I have 2 third party shared libraries: libA.so and libB.so. My program contains only calls to libA.so symbols. The libA.so internaly needs to call to libB.so. If I readelf LibA.so it has a RunPath pointing to a path from…
2
votes
2 answers

How to set CMAKE_INSTALL_RPATH with multiple directories?

On the question CMAKE RPATH not working - could not find shared object file I see how to set CMAKE_INSTALL_RPATH for a single path, but I need it for multiple paths. I tried these using but I did not worked: SET( CMAKE_INSTALL_RPATH…
Evandro Coan
  • 8,560
  • 11
  • 83
  • 144
2
votes
1 answer

how to get Xcode to set LC_RPATH (so that @rpath loads will work)?

I want to make a command-line tool with a few bundled frameworks that it needs (SDL and related libs). I have Xcode set to "Embed & Sign" these frameworks, and this results in them being copied to the build folder next to the executable. The…
Joe Strout
  • 2,634
  • 2
  • 28
  • 39
2
votes
1 answer

Does @rpath work for looking up .dylibs that are loaded/called from another .dylib?

I just found about the @rpath to load .dylib files using dlopen, and need some help understanding them. I am using Xcode 3.2.5 on a OSX machine. I have several .dylib's that call other .dylib's, and which also call each other. The @rpath seems to…
Michael Wildermuth
  • 5,762
  • 3
  • 29
  • 48
2
votes
1 answer

LD_PRELOAD changes the LD_LIBRARY_PATH

I am having a peculiar problem. I have a shared library 'my_tracker.so' that I built using gcc-4.2. This shared library now has a dependency on libgcc_s.so.1 (GCC 4.2). I did 'ldd my_tracker.so' and it picked up libgcc_s.so.1 from /lib64. I am…
johnm
  • 21
  • 2
2
votes
1 answer

Bazel - how to deal with transitive dependencies of external .so libraries?

I'm trying to build a binary application with Bazel. This binary depends on an external, pre-compiled library, let's call it liba.so. In turn, liba.so depends on libb.so (this information I obtain via readelf -d liba.so | grep NEEDED. To build this,…
user1011113
  • 1,114
  • 8
  • 27
2
votes
1 answer

Setting rpath for dependencies of dependencies?

I've got a Linux executable build going where I've set the rpath through the linker flags "-Wl,-rpath,./ -Wl,--disable-new-dtags", and I've verified through readelf -d that the RPATH is being set to ./ This works for direct dependencies, as my…
Archduke
  • 333
  • 1
  • 10
2
votes
3 answers

Compiling Python 2.6.6 and need for external packages wxPython, setuptools, etc... in Ubuntu

I compiled Python 2.6.6 with google-perf tools (tcmalloc) library to eliminate some of the memory issues I was having with the default 2.6.5. After getting 2.6.6 going it seems to not work becuase I think having issues with the default 2.6.5 install…
J Spen
  • 2,614
  • 4
  • 26
  • 41
2
votes
1 answer

G++ 4.9.2 and 8.2.0 - final binary's dependency with default lib path searching ./../lib directory (implicit RPATH issue)

I encountered an odd difference between the binary produced by a 4.9.2 G++ and a 8.2.0 G++ on a Linux, when upgrading from the former to the latter. I was able to narrow it down to the below minimized snippet //main.cpp int…
searchengine27
  • 1,449
  • 11
  • 26
2
votes
2 answers

cpack (creating RPM) ignores CMAKE_INSTALL_RPATH (sets RPATH to empty string - rather than an explicit value)

I'm trying a fairly simple experiment using cpack. The aim is to create an RPM installer (using cpack) with a trivial executable which uses an external 3rd party shared library (called libSomeSharedLib.so). The structure I'd like the RPM to install…
BenF
  • 71
  • 7