Recent

Author Topic: Problem with bundling frameworks for app built via FPC through Xcode  (Read 5452 times)

Christian Knudsen

  • Newbie
  • Posts: 5
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?

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 1058
Re: Problem with bundling frameworks for app built via FPC through Xcode
« Reply #1 on: February 19, 2015, 02:52:08 pm »
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).

Christian Knudsen

  • Newbie
  • Posts: 5
Re: Problem with bundling frameworks for app built via FPC through Xcode
« Reply #2 on: February 19, 2015, 03:22:08 pm »
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

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 1058
Re: Problem with bundling frameworks for app built via FPC through Xcode
« Reply #3 on: February 19, 2015, 03:30:57 pm »
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

Christian Knudsen

  • Newbie
  • Posts: 5
Re: Problem with bundling frameworks for app built via FPC through Xcode
« Reply #4 on: February 19, 2015, 03:36:56 pm »
@loader_path/../Frameworks

Christian Knudsen

  • Newbie
  • Posts: 5
Re: Problem with bundling frameworks for app built via FPC through Xcode
« Reply #5 on: February 19, 2015, 03:47:16 pm »
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?

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 1058
Re: Problem with bundling frameworks for app built via FPC through Xcode
« Reply #6 on: February 19, 2015, 03:53:34 pm »
* 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")

Christian Knudsen

  • Newbie
  • Posts: 5
Re: Problem with bundling frameworks for app built via FPC through Xcode
« Reply #7 on: February 19, 2015, 03:59:40 pm »
* 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

 

TinyPortal © 2005-2018