Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embedding frameworks in a Mac App Bundle

I'm trying to add SDL and SDL_ttf frameworks to my application and I've done it the usual way: added them in the "Link Binaries with Libraries" section and added a copy files phase that copies them to the Frameworks directory. This does create a app bundle with embedded frameworks. However, when I run the application, I get this error:

dyld: Library not loaded: @rpath/SDL_ttf.framework/Versions/A/SDL_ttf Referenced from: /Users/matthew.davies/Library/Developer/Xcode/DerivedData/MacHub-ambfqujqxbxyiqapaoctvsucpdeu/Build/Products/Release/MacHub.app/Contents/MacOS/MacHub Reason: image not found

I am not sure what else to do so that the app can find the frameworks despite being embedded in its bundle.

Any ideas please?

like image 752
Cthutu Avatar asked Sep 19 '12 16:09

Cthutu


People also ask

How do I embed a framework?

Adding A Framework TargetCreate a new Xcode target and select the framework template appropriate for your app's target platform. Add all of the framework source files to the new target's Compile Sources build phase. Set the visibility of header files needed by clients of the framework to Public.

How do I embed a framework in Xcode?

You just need to go in your target -> build settings -> Linking -> Mach-o-Type. You can CHANGE the type of the framework to any other options. When you create a framework from Xcode it'll automatically set it to a dynamic library, but you can change it for whatever you want, as the image below shows.

What are frameworks on Mac?

A framework is a hierarchical directory that encapsulates shared resources, such as a dynamic shared library, nib files, image files, localized strings, header files, and reference documentation in a single package. Multiple applications can use all of these resources simultaneously.

Where are frameworks stored macOS?

Apple keeps frameworks in /System/Library/Frameworks/ and /System/Library/PrivateFrameworks/. Inside these directories are *. framework files, which are themselves a directory of computing resources (binary executables, dynamically linked libaries, headers, etc.).


1 Answers

I discovered the reason why in a comment on a webpage. I needed to set the "Runpath Search Paths" build setting to "@loader_path/../Frameworks" and the frameworks are found.

Why frameworks are not automatically searched for in the Frameworks directory of an app bundle is a complete mystery to me? Are you listening Apple? :)

like image 77
Cthutu Avatar answered Oct 06 '22 05:10

Cthutu