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
0
votes
3 answers

Link libraries to linux biinary file in c++

I'm compiling a c++ program using g++ and i am using two libraries called libsdl2-dev and libsdl2-image-dev I installed both these libraries in my ubuntu machine with the commands apt install libsdl2-dev libsdl2-image-dev and when I compile the…
Kiriaevi
  • 5
  • 2
0
votes
1 answer

Changing library search paths by install_name_tool

otool -L dependencies for a binary: $ otool -L libeditorlib.dylib libeditorlib.dylib: libeditorlib.1.dylib (compatibility version 1.0.0, current version 1.0.0) @rpath/libtbb.dylib (compatibility version 0.0.0, current version 0.0.0) …
Megidd
  • 7,089
  • 6
  • 65
  • 142
0
votes
1 answer

Cmake set relative path to binary to 3rd party library

I'm trying to make my first roject using Cmake and I'm faced with issue with static linking to *.so library. My binary see libraries only from the build folder. I've tried to use this statements from "RPATH handling" manual, but it's not working so…
Demetera
  • 53
  • 1
  • 8
0
votes
0 answers

Why my executable runs with `RPATH` but not with `RUNPATH`

I build an executable app that uses liba. liba in turn needs libb. libb in turn needs libc. The dependency looks like this: app -> liba -> libb -> libc. The app and liba are built by me while libb and libc are 3rd party. I do not know how they were…
nikitablack
  • 4,359
  • 2
  • 35
  • 68
0
votes
2 answers

Cmake: setting rpath

I'm trying to switch from GNU Make to CMake on a C++ project. My plan is to distribute alongside the source code of my library, also the code of two external libraries that are needed. The project is structured as follows ├── CMakeLists.txt ├──…
mariob6
  • 469
  • 1
  • 6
  • 16
0
votes
1 answer

Library load error when compiled with -fvisibility=hidden in Linux

We face an issue with our shared library linked statically with OpenSSL. The library is used in Apache HTTP Server.Although we have compiled our shared library statically with OpenSSL, it was using system OpenSSL library path, which the web server…
George Thomas
  • 67
  • 1
  • 12
0
votes
0 answers

How rpath and sys/types.h are related?

After adding "-Wl,-rpath,." into CMAKE_EXE_LINKER_FLAGS next call in CMakeLists started returning false: check_include_file_cxx(sys/types.h HAVE_SYS_TYPES_H) How rpath and sys/types.h are related?
0
votes
2 answers

Is there a way in rPATH's conary recipe to get the verison of an existing package

i am trying ... loadRecipe('existingpackage') class NewPackage(PackageRecipe): name = 'newpackage-test' p = existingpackage.version print p but getting error, that existingpackage is not defined
kamal
  • 9,637
  • 30
  • 101
  • 168
0
votes
1 answer

CMake DragNDrop framework rpath for qt not set when targeting package

When creating a DragNDrop bundle of my project using the qt framework provided by brew qt5.13.0 the rpath does not seem to be honored although I am setting it to the path I copy the Framework to in my bundle. I have tried set(MACOSX_RPATH ON) and…
Russel Waters
  • 111
  • 1
  • 5
0
votes
0 answers

Unable to link libssl to libcrypto

I have created an application where it uses libssl which apparently uses libcrypto. I have kept these libraries at a user-defined location…
RC0993
  • 898
  • 1
  • 13
  • 44
0
votes
0 answers

CMake link shared library to system version instead own

I have my own libusb version inside the project's source directory, that I find with: find_path(LibUsb_INCLUDE_DIR NAMES libusb.h PATHS ${CMAKE_CURRENT_SOURCE_DIR}/LibUsb/Include) if(NOT LibUsb_INCLUDE_DIR) message(FATAL_ERROR "LibUsb: include…
galah92
  • 3,621
  • 2
  • 29
  • 55
0
votes
2 answers

RPATH equivalent for executables

I have a c++ shared library which as part of its normal behaviour fork()/execs() another executable containing some unstable legacy code. This executable is not useful other than with this library, so I'd like to avoid placing it in a PATH…
tgoodhart
  • 3,111
  • 26
  • 37
0
votes
0 answers

rpath not set in complicated make command (appears twice, first takes precedence?)

I am working with a large CMake project, and trying to debug why an rpath in a shared library is not getting set at all. Digging through the verbose output, the build command can be found to be: /usr/bin/c++ -fPIC -DVERSION_INFO=\"0.0.1\" -fPIC…
Ben Farmer
  • 2,387
  • 1
  • 25
  • 44
0
votes
1 answer

Discrepancy in behavior of Linux loaders (ld-linux-x86-64) between Glibc 2.12 and Glibc 2.17

I'm trying to compile the same lib on two x86 separate machines. Both use the same toolchain (exactly same set of files) but have different Glibc versions. When I run command LD_DEBUG=libs /lib64/ld-linux-x86-64.so.2 --list ./libl2ps.so I notice the…
frperies
  • 41
  • 6
0
votes
1 answer

Library not loaded: @rpath/libboost_thread.dylib

I built a boost python based .so file with help of the boost Jamroot for using the .so within Python. When I import the library in Python I get the following error: import vision_library ImportError:…
ssk
  • 9,045
  • 26
  • 96
  • 169