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

CMake, OSX, the @rpath, and linking to frameworks

I've spent a week trying to get something that I got working on Linux to work on OSX, but to no avail. I've tried reading the CMake article on the rpath and various other SO posts regarding it and mucking about with my CMakeLists.txt to get it to…
sonictk
  • 178
  • 2
  • 10
7
votes
2 answers

Cmake not setting RPATH when adding link_library with -L

When setting link libraries in the following manner target_link_libraries (SOME_TARGET -L/somedir -lfoo) cmake doesn't handle RPATHs. Is using '-L' and '-l' not best practice, or actually plain wrong? When creating my own Find*.cmake I usually use…
hbogert
  • 4,198
  • 5
  • 24
  • 38
7
votes
0 answers

Propagation of rpath in library fails

Short question: Are the rpaths from a LC_RPATH command inside a library passed onto subsequent (and indirect) dynamically loaded libraries? To be more precise: I have libapi.dylib dynamically linked to libloader.dylib which in turn dynamically loads…
phlipsy
  • 2,899
  • 1
  • 21
  • 37
6
votes
2 answers

CMAKE RPATH with packaging

I am creating package using cmake I am having following structure bin/ bin1 lib/ lib1 lib2 Where lib1 and lib2 are external dynamic library. How can I set RPATH so it will automatically link with lib1 and lib2 ?
Vivek Goel
  • 22,942
  • 29
  • 114
  • 186
6
votes
1 answer

Cocoapods dyld: Library not loaded @rpath Image not found

I am currently using Xcode 8.1, cocoa pods 1.2.0.beta.1, and launching my app on a simulator with iOS 10.1. My app builds just fine, however after launching the app in a simulator, I receive the following error: dyld: Library not loaded:…
jeremyms
  • 319
  • 2
  • 11
6
votes
2 answers

Build OpenSSL with RPATH?

I have Ubuntu 14.04. It came with openssl 1.0.1f. I want to install another openssl version (1.0.2) and I want to compile it by myself. I configure it as follows: LDFLAGS='-Wl,--export-dynamic -L/home/myhome/programs/openssl/i/lib…
damixxx
  • 81
  • 1
  • 3
6
votes
1 answer

Reliable Deployment of Delphi-Generated Dylib on OSX

I would like to deploy a .dylib on OSX, which has been created with Delphi. This .dylib should be loadable by third-party applications. This is going to seem like a duplicate question, but after plenty of searching, I can't find an answer for it. …
AudioGL
  • 494
  • 4
  • 18
5
votes
0 answers

RPATH propagation failing for Python bindings

I am building a library (Ubuntu 22) that uses onnxruntime under the hood. In turn, onnxruntime uses CUDA, dynamically loading some dedicated "backend". I build the whole code stack except the CUDA libraries, and none of the libraries have their…
ajc
  • 365
  • 2
  • 18
5
votes
1 answer

Cmake on mac os x, link libraries with fullpath

I'm trying to build a python extension with cmake. This is the cmake list: cmake_minimum_required(VERSION 2.8) PROJECT(drtile) set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}) find_package(Vigra REQUIRED) find_package(Boost COMPONENTS python…
Luca Fiaschi
  • 3,145
  • 7
  • 31
  • 44
5
votes
1 answer

CMake not adding full RPATH on macOS

I have the following MWE where Conan is used to install the fmt library (shared). cmake_minimum_required(VERSION 3.21) project(Test CXX) set(CMAKE_MACOSX_RPATH ON) set(CMAKE_CXX_STANDARD 17) list(APPEND CMAKE_MODULE_PATH…
Gabriel
  • 8,990
  • 6
  • 57
  • 101
5
votes
0 answers

Attempt to use dylib dynamic library in cgo fails, report “dyld: Library not loaded”

I tried to import the dylib dynamic library in cgo, but it failed. Here is my code. package main //#cgo CFLAGS: -I./yun2txt/include //#cgo LDFLAGS: -L./yun2txt/lib -ltotxt // //#include import "C" func main() { C.hello() } There…
李逍遥
  • 51
  • 1
5
votes
1 answer

How to link custom framework within UITest target in Xcode - another "Library not loaded - @rpath"-issue

My project uses Xcode 11.3.1 and is structured as followed: MyProject - MyProject.xcworkscapce - MyFramework - MyApp -MyApp (main-target) -MyAppUITests (uiTest-target) MyApp imports MyFramework and can be built und run just fine. For this…
nayooti
  • 395
  • 2
  • 15
5
votes
1 answer

How to avoid 'cannot open shared object file' when using CMake?

Situation My project uses CMake and compiles without problems on Ubuntu 16.04. When starting the compiled application I get the message cannot open shared object file. All the shared object libs are available in the same non-standard folder (and I…
mz1000
  • 87
  • 1
  • 6
5
votes
2 answers

Linking is jacked up.. what is -rpath? MacOS X

So, I'm building a project, and it uses functions from a compiled library (.dylib or .so). I have the headers and the library files (this is all part of QtRoot, btw) in appropriate locations, but when I try to build my project in Xcode, I get a…
PTTHomps
  • 1,477
  • 2
  • 22
  • 38
5
votes
3 answers

Custom framework not loaded dyld: Library not loaded: @rpath/Custom.framework/

I have an app with several custom dynamic frameworks which means I am using iOS 8 as the SDK on Xcode 6.2. My Mac is on Yosemite. The frameworks have Swift sources and resources. The app is distributed enterprise so I just create an IPA and…
naz
  • 1,478
  • 2
  • 21
  • 32
1 2
3
14 15