Linking is jacked up.. what is -rpath? MacOS X
Asked Answered
M

2

5

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 debugger error:

dyld: Library not loaded: @rpath/libRIO.so Referenced from: /Users/paulthompson/Documents/Programming/Build Products/Debug/MacHeliosSim.app/Contents/MacOS/MacHeliosSim Reason: image not found sharedlibrary apply-load-rules all Data Formatters temporarily unavailable, will re-try after a 'continue'. (Cannot call into the loader at present, it is locked.)

Now, the program itself which is built will run just fine if I open it from the Finder, but whenever I try to run it from Xcode, it barfs at me. What is this rpath thing, and why can't the debugger find the libraries, even though Xcode itself knows where they are, and apparently the program when run from the Finder can find them too?

Molar answered 12/8, 2010 at 1:38 Comment(0)
D
3

http://en.wikipedia.org/wiki/Rpath_(linking)

It's a path stored in the binary to find shared libs. When you start the app from Finder, it's probably an app bundle? When app bundles are created, shared libraries are copied into the app bundle, and the paths to the bundled libraries become relative then. (@executable_path/../Frameworks/foobar). How did you create the version that works from Finder?

Does the error above occur at link-time or when starting the application from xcode? (In the latter case, try with DYLD_LIBRARY_PATH)

Also, the .so extension for libRIO instead of .dylib looks a bit suspicious.

Disloyalty answered 12/8, 2010 at 6:42 Comment(4)
You missed the closing parenthesis on your link.Tatum
Correct, it is a .app bundle. However, none of the shared libraries are in it, unless they get wrapped into the actual binary. There isn't even a frameworks directory... Anyway, the .app is created by doing either 'build' or 'build and go' from Xcode. The error crops up during the go portion of 'build & go' or if I select run from within Xcode. The .so, I think, is actually a sym link to the .dylib. Some of the library files I'm linking to are actual .so files, and others are .dylib. I think there are even some .a's in there somewhere, but I may be wrong. So, am I perhapse missing aMolar
I suppose I should ask, what is the correct way to add a precompiled library like this to a project? The method I used was to drag and drop them from another project (which was generated by qmake, and displays the same problem). Also, that wiki article is rather brief. Can you expound a bit on the details of rpath?Molar
This explains what rpath is but fails to address how to fix the problem.Iridis
C
2

Add the rpath in the linking phase, like in this (in qt creator) example:

LIBS += -L/usr/local/root/lib -lGui -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -lpthread -Wl,-rpath,/usr/local/root/lib -lm -ldl

Cohn answered 26/1, 2012 at 17:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.