PDA

View Full Version : Mac OS X app bundle can't find bundled framework files



Christian Knudsen
18-02-2015, 10:04 PM
I'm trying to make a bundle of my Mac OS X app compiled by Free Pascal through Xcode. I've got SDL2, SDL2_mixer and SDL2_image in the Frameworks folder of my app bundle. But the app can't find them. The SDL2 binaries all have "@rpath/SDL2.framework/Version/A/SDL2" as their install names, so setting "Runtime Search Paths" in Xcode to "@executable_path/../Frameworks" should mean that the compiled binary can find the frameworks. But it still can't. So is there some issue with compiler parameters set in Xcode not being passed on to Free Pascal?

phibermon
19-02-2015, 09:03 AM
Don't know about Xcode, it is a pre-requisite but I'm pretty sure that the Xcode development environment itself and any configuration are totally ignored by Freepascal + Lazarus. I believe Freepascal makes use of the linker, debug symbols etc that come with Xcode and that's it. (for IOS development you're using XCode in the chain given the deployment restrictions)

What I do know for certain is that using Lazarus on OSX, I had no problem at all using libs packaged inside the bundle.

Due to using Lazarus as my IDE and not having any such problems, I've not looked into how these paths are defined during the compilation process.

It is almost certainly the case that you're looking to set Freepascal options and not Xcode options - Freepascal is the compiler and I can't think of any good reason why it would read Xcode configurations over defining its own. In an ideal world Xcode wouldn't be needed at all - They'd be working to be free of the dependency, not get further in bed with it.

So look into Freepascal and OSX platform specifics - It'll be some compiler parameter or other and don't expect Xcode to have any knowledge of Freepascal in order to pass the parameter. I may be wrong of course but given you're doing it by the book in Xcode and it's still not working? I'm probably right.

If XCode can support third party compilers it'll have functionality to pass parameters, set environment variables etc which you can make use of - perhaps even the "Runtime search paths" as a variable you can pass as the relevant option to the compiler.

Christian Knudsen
19-02-2015, 09:31 AM
Thanks for you reply. Yeah, it definitely does seem like I have to pass this stuff on to Free Pascal manually. I'll look into it. :)

phibermon
19-02-2015, 09:45 AM
Sorry I couldn't give you specifics.

Ascii Sector is seriously cool by the way :D

Christian Knudsen
19-02-2015, 11:09 AM
Thanks! I'm going insane trying to get the new version to work on Mac OS X, though. :(

From advise elsewhere, it does seem like Xcode's linking phase should have an affect, which makes sense, since I believe the whole point of doing this through Xcode is to use its linker. So now I'm stuck again.

phibermon
19-02-2015, 01:43 PM
Hmm. I've googled like a mad man and I've only managed to find the following pages that bare any resemblance to your problem :

http://stackoverflow.com/questions/9258973/dylib-made-with-delphi-xe2-cannot-be-used-by-xcode-app

http://forum.lazarus.freepascal.org/index.php?topic=20252.0

along with the compiler directive {$linklib}

also I had a problem with relative paths in bundles long ago during debugging/executing from my IDE (but it was my data files and not a lib) does it still happen when you run the bundle directly?

Try an absolute path to a point in your file-system rather than the relative "@executable_path/../Frameworks"

If an absolute path doesn't work then either the SDL2 libs you have are not valid (32bit vs 64bit?) or that directory is simply not being passed to the linker.

Perhaps installing Lazarus and compiling there - see if you can replicate the problem. Also while it can't find the libs in the path you specify, perhaps it is looking elsewhere, try placing them at the root of the bundle, next to the binary etc. Perhaps the default path will be one of these.

I think it would be worth eliminating those dynamic libs as the source of the problem (although to be fair they're likely fine) perhaps an existing SDL2 mac game/program that you can examine/swap files in.

Can OSX have shared libraries in a system location? if so, try putting the SDL2 libs there which should definitely work - I know you want to bundle it all together but it will at least confirm this is a path issue and not something we're not guessing.

phibermon
19-02-2015, 01:48 PM
It would help if we understood the nature of the relative paths etc

it might be worth getting an existing SDL2 bundle online and just swapping in your binary - perhaps the path isn't compiled into the binary at all, perhaps it's defined in some other file in the bundle.

If needs be I'll fire up my Hackintosh and attempt to replicate your conditions

Christian Knudsen
19-02-2015, 02:18 PM
Everything runs fine if I have the SDL2 frameworks in /Library/Frameworks.

But trying to find en existing SDL2 bundle and see if I can just use the frameworks from that is a brilliant idea. I'll see if I can find one. (Though I'm just using the SDL2 frameworks downloaded directly from libsdl.org and if they can't be bundled with my app, it must be a problem with my app and not the frameworks?)

Christian Knudsen
19-02-2015, 03:01 PM
Yes!

Adding -k"-rpath @executable_path/../Frameworks" as a custom linker option for FPC did it!

:D

So the linker parameters weren't passed on from Xcode to Free Pascal. At this point I'm wonder what exactly I'm using Xcode for?!