@rpath for a dynamic library embedded in a framework
Asked Answered
J

1

15

I have an app, call it Animal.app. Inside its Contents/Frameworks folder is a framework, say Mammal.framework. And inside the Versions/A/Frameworks folder of the framework, I have dog.dylib. The install name of dog.dylib is @rpath/dog.dylib. For the "Runpath Search Paths" setting of the framework, I have specified @loader_path/../Frameworks. (My reasoning for that last setting is that the "loader" of the dylib would be the binary of the framework, at the path Mammal.framework/Versions/A/Mammal.)

I get an error message at runtime:

Dyld Error Message:
  Library not loaded: @rpath/dog.dylib
  Referenced from: /Volumes/VOLUME/*/Animal.app/Contents/MacOS/../Frameworks/Mammal.framework/Versions/A/Mammal
  Reason: image not found

I've read Apple's "Run-Path Dependent Libraries" documentation, and Mike Ash's blog post on @rpath, but I still can't see what I'm doing wrong.

Jukebox answered 23/10, 2012 at 1:11 Comment(0)
J
9

It turns out that the right runpath search path is @loader_path/Frameworks. What I was missing is that @loader_path represents, not the full path to the loader, but that path minus its last component. Mike Ash's blog post does say that, but I somehow missed it. Thus, in the case of a framework, @loader_path ends with the A.

Jukebox answered 24/10, 2012 at 21:47 Comment(3)
Yes, to be clear: the Installation Directory for both your nested dylib and its parent framework should be "@rpath". The parent framework then includes "@loader_path/Frameworks" in its Runpath Search Paths (since the dylib ends up as a sibling of the Frameworks folder); the app using this framework includes "@loader_path/../Frameworks" (since the executable is down in MacOS). The app could use @executable_path just as well, but @loader_path seems cooler :-)Strander
I don't understand what you actually did to make it work... explain it to me like I'm 6.Peterman
@Prof.Falken: In the build settings for the framework, under Linking, there is a setting called "Runpath Search Paths". I set its value to @loader_path/Frameworks.Jukebox

© 2022 - 2024 — McMap. All rights reserved.