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

How do I know how ldd resolved the dependency

For a dependency identified by ldd, how do I know whether it used the binary's RPATH or the environment's LD_LIBRARY_PATH ?
MartinCz
  • 528
  • 4
  • 13
3
votes
0 answers

C++ python module linking on MacOS

I'm building a C++ python module on MacOS. On my machine I have python, installed in directory /Library/Frameworks/Python.framework/Versions/3.9. I'm specifing python includes directory as -I/Library/Frameworks/Python.framework/Versions/3.9/Headers…
David
  • 39
  • 2
3
votes
1 answer

Lookup failure when linking using -rpath and $ORIGIN

I'm trying to learn how to use the -rpath option in GCC's linker (ld) with $ORIGIN. I'm trying the simplest example I can think of (see below), and all the links I read seem to say I'm doing it correctly. However, when I run the executable it can't…
Simon
  • 623
  • 1
  • 8
  • 13
3
votes
2 answers

How to manually include a dynamic library in an iOS APP

I have an iOS app (not made with xcode) and I need to include in it a dynamic library. I have this library on my computer: \webrtc \WebRTC.framework \Headers \*.h \Modules \module.modulemap …
zeus
  • 12,173
  • 9
  • 63
  • 184
3
votes
0 answers

CMake use rpath for linked libraries instead of the full path

For simplicity, here's an example of what I'm trying to achieve: CMakeLists.txt: cmake_minimum_required(VERSION 3.9) project(example) add_library(${PROJECT_NAME} SHARED) target_link_libraries(${PROJECT_NAME} PUBLIC…
martin
  • 1,007
  • 2
  • 16
  • 32
3
votes
0 answers

How to remove absolute path in shared library linked by LLVM LD

In Mac OS X, when using LLVM LD to link some C code (which will result in a shared library called libA.so) that has a dependency to a shared library called libX.so, the absolute full path of libX.so is included in the list of shared libraries that…
user7698505
3
votes
3 answers

Developing Qt applications in Unix systems using Qt Creator

I'm developing a Qt application in Linux using Qt Creator (2.1 RC). I've created 2 projects, and used the wizard to add the library project to the application project. However when I run it, I receive the…
Jake Petroules
  • 23,472
  • 35
  • 144
  • 225
3
votes
0 answers

Can I provide absolute path for .dll at compile time in windows?

I created one .dll(Dynamic link library). Using this library I want create executable file. But I want to provide absolute path for .dll to link with .exe. So when I execute .exe it links with .dll. I don't want to set PATH(environment variable),…
Pankaj Vavadiya
  • 481
  • 7
  • 15
3
votes
0 answers

Incongruence with dynamic library directories in MAC

I am trying to include a dynamic library in my project and I am setting up the compilation using the following CMake script: find_package( DLIB 18.18.0 REQUIRED ) include_directories( ${DLIB_INCLUDE_DIRS} ) add_executable( executable executable.cxx…
Edu
  • 178
  • 1
  • 7
3
votes
1 answer

What are the recommended GNU linker options to specify $ORIGIN in RPATH?

Assume my platform is vanilla (non-embedded) x86-64 Linux using GNU build toolchain (GCC, etc.). To specify $ORIGIN in RPATH, I know about the linker option: -Wl,-rpath,'\$\$ORIGIN'. Today, I discovered another option: -Wl,-z,origin. Should I always…
kevinarpe
  • 20,319
  • 26
  • 127
  • 154
3
votes
1 answer

How to handle problems with RPATH on Mac OS X while installing cmocka?

I am trying to install and run cmocka library for unit testing on Mac OSX Yosemite 10.10.3, but I've got some problems with the RPATH settings. Update: Thanks to @baf, I was able to include cmocka.h in my CMakeLists.txt manually like…
Mateusz Piotrowski
  • 8,029
  • 10
  • 53
  • 79
3
votes
3 answers

CMake cross compile target rpath

I am cross-compiling using CMake. In my CMakeLists.txt (used for both compile and cross compile): set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) find_package(foo REQUIRED) add_library(mylib SHARED ${SRCS}) target_link_libraries(mylib…
explo91
  • 530
  • 4
  • 11
3
votes
1 answer

OS X: dylib rpath wrong after compiling

I'm building cyrus sasl2 libraries from source. The libs get installed in /usr/local/lib, and the headers in /usr/local/include/sasl, which is proper. However, when I run apps that try to use them, I get: dyld: Library not loaded: /libsasl2.dylib …
AaplMike
  • 343
  • 1
  • 4
  • 15
3
votes
2 answers

RPATH failed to expanding

I have built an executable (named demux) on OS X that always fails to load and I cannot find why: $ ./demux RPATH failed to expanding @rpath/sfeMovie.framework/Versions/2.0/sfeMovie to:…
Ceylo
  • 362
  • 2
  • 11
3
votes
2 answers

Unable to remove rpath from executable

I am cross-compiling for an ARM platform. Amongst the many library files I'm linking, only a very few of them have an rpath. I don't know where it is coming from, because I copied all libraries I needed into a single folder, and add them to the…
Bob
  • 10,741
  • 27
  • 89
  • 143