Confused Development

I develop software and I often get confused in the process. I usually find the answers after a while, but a month later I can't remember them. So from now on, I will write them down here.

Wednesday, March 29, 2006

Embeddable Frameworks in Cocoa

In Cocoa, class libraries are called Frameworks (actually, Frameworks can be a bit more than just compiled code). Frameworks can be configured such that you can embed them into an application, relieving your users from having to install the framework. However, for this to work, one has to make sure to adjust the relevant build settings correctly. Otherwise you will get the horrible "dyld: Library not loaded:" error. I have done this several times already in the past, but every time the problem pops up, I have forgotten how to do it again.

Jonathan Rentzsch apparently had the same problem and has therefore recorded a little movie on how to do it. How great is that! The movie explains in detail the how to adjust the build settings in XCode. There is just one little thing I would like to add, as a note to self: in XCode (im currently using 2.2.1) you can access the build settings of the target build and of the project itself. I have no clue what the latter are for, but setting them won't help you. At least they didn't for me. Instead, make sure you adjust the settings for the target.

The right build settings in XCode 2.2.1

One other thing I found (in the cocoadev wiki) is a nice way of checking if you actually succeeded. Once you have built your embeddable framework and the application that embeds it, you can use the otool command line tool to find out where your application will actually look for the libraries it needs.

otool -L semiBlog.app/Contents/MacOS/semiBlog
semiBlog.app/Contents/MacOS/semiBlog:
        @executable_path/../Frameworks/XMLRPC.framework/Versions/A/XMLRPC
        /System/Library/Frameworks/WebKit.framework/Versions/A/WebKit

Embedded frameworks will have a relative path starting with "@executable_path" (the applications path), others will have an absolut path.

And just to give credit: the XMLRPC framework that is mentioned in the examples is Eric Czarny's work. I just made it embeddable!