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?

Cœur
  • 37,241
  • 25
  • 195
  • 267
PTTHomps
  • 1,477
  • 2
  • 22
  • 38

2 Answers2

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.

Frank Osterfeld
  • 24,815
  • 5
  • 58
  • 70
  • You missed the closing parenthesis on your link. – Adam W Aug 12 '10 at 17:01
  • 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 a – PTTHomps Aug 12 '10 at 21:28
  • 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? – PTTHomps Aug 12 '10 at 21:31
  • 1
    This explains what rpath is but fails to address how to fix the problem. – tgunr Mar 27 '18 at 20:52
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

Aliaksei Kliuchnikau
  • 13,589
  • 4
  • 59
  • 72
Marco
  • 21
  • 1