9

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?

insys
  • 1,288
  • 13
  • 26
Cthutu
  • 8,713
  • 7
  • 33
  • 49

1 Answers1

7

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? :)

Cthutu
  • 8,713
  • 7
  • 33
  • 49
  • 1
    If you build things the way Apple recommends, it will end up looking for `@loader_path/../Frameworks/SDL.framework` in the first place, so you won't need it on the search path. This is a safer solution, because it guarantees your app won't end up linked to the wrong version of the framework. If you don't do things the way they recommend… well, then you have to learn all kinds of low-level details. (What you probably really want here is `install_name_tool`, but the odds of you finding that out for yourself without knowing in advance are slim…) – abarnert Sep 19 '12 at 20:16
  • 1
    The real problem here is that Apple has good documentation for the very simple "getting started" use of frameworks, and for the low-level details of how it all works, but not much in between… – abarnert Sep 19 '12 at 20:16
  • In my project, the executable was picking up both the /Library/Frameworks and the app Contents/Frameworks copies of the framework, and was warning that the library selection would be undefined (in fact, SDL_Mixer didn't work in this configuration). This tip fixes that problem, too. – Justin Aug 23 '13 at 18:23
  • Just checking - I want to link 3rd party frameworks in my framework. Currently I need to give my customers my framework and every framework I link in my framework. I'm looking for a means to package it all up in my framework, so my customers do not have to link to those 3rd party frameworks. Is that what you are attempting to do in this question? If so, I'd like to get more information from you. Willing to ask a question for you at your request. – Patricia Aug 06 '14 at 19:56
  • No, the question was asking how the application finds those frameworks that are already packaged in the app. To package you have to link with them in Xcode and add them in a copy files build phase. But even though your app bundle has the frameworks, they were not found. This question addresses that problem. – Cthutu Aug 14 '14 at 15:29