Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 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?

like image 352
TraxusIV Avatar asked Aug 12 '10 01:08

TraxusIV


2 Answers

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.

like image 91
Frank Osterfeld Avatar answered Sep 25 '22 12:09

Frank Osterfeld


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

like image 29
Marco Avatar answered Sep 23 '22 12:09

Marco