Lazarus
Programming => Operating Systems => macOS / Mac OS X => Topic started by: Christian Knudsen on February 19, 2015, 02:40:32 pm
-
I know this isn't a Lazarus question as I'm using Xcode, but everywhere else I've asked it, they didn't know what was wrong, so now I'm trying here...
I've got an app that I've compiled with Free Pascal through Xcode. The app runs fine, but when I try to bundle the SDL2, SDL2_image and SDL2_mixer frameworks into the bundle, it can't find them. The problem seems to be in setting the Runtime Search Path (@rpath) to expand to @loader_path/../Frameworks. In Xcode, I've set everything as people have told me to, but the bundled app still can't find the bundled frameworks:
dyld: Library not loaded: @rpath/SDL2.framework/Versions/A/SDL2
Referenced from: /Users/mac/Desktop/Ascii Sector.app/Contents/MacOS/./asciisec
Reason: image not found
Trace/BPT trap
Anybody here have had similar problems getting a bundled app to find the bundled frameworks?
-
What is the install name of the frameworks themselves? The install name of the framework in your program and the one in the framework itself must match. See e.g. https://blogs.oracle.com/dipol/entry/dynamic_libraries_rpath_and_mac for some background (the article is about dynamic libraries, but frameworks are just dynamic libraries inside a specific directory layout).
-
The install name of the SDL2 binary inside the SDL2.framework (that's what you meant, right?) is:
macs-Mac:SDL2.framework mac$ otool -D SDL2
SDL2:
@rpath/SDL2.framework/Versions/A/SDL2
-
And what did you pass as -rpath option when linking your application? "In Xcode, I've set everything as people have told me to" is about as vague as you can be. See also https://mikeash.com/pyblog/friday-qa-2009-11-06-linking-and-install-names.html
-
@loader_path/../Frameworks
-
How would I set rpath as a command line parameter for the Free Pascal compiler in case it isn't passed on by the Xcode linker?
-
* Try -rpath @executable_path/../Frameworks
* Make sure that all dependencies between SDL2 and SDL_image (and other frameworks you include) are also relative to @executable_path (otherwise a dependency of SDL_image on SDL2 will be looked for relative to the load location of SDL_image instead of relative to your binary -- see the blog post referenced in my previous message). Check the otool -L output when run on your framework libraries.
* Also verify that your framework contains the correct architectures for your binary (use the "file" command to see which architectures your libraries contain).
* to specify custom linker options via FPC: use the -k parameter, e.g. -k-rpath -k@executable_path/../Frameworks (or, probably also, -k"-rpath @executable_path/../Frameworks")
-
* to specify custom linker options via FPC: use the -k parameter, e.g. -k-rpath -k@executable_path/../Frameworks (or, probably also, -k"-rpath @executable_path/../Frameworks")
Yes! That did it! You're a life saver!
:D