Objective-C static libraries and categories

If you are building iPhone or other Mac apps with the iPhone using static libraries, reading
Technical Q&A QA1490 will help you. I was getting a problem running with FMDB because it uses categories to extend the functionality of one of its classes and failing at runtime with a selector problem.

To resolve this issue, the static library should pass the -ObjC option to the linker. This flag causes the linker to load every object file in the library that defines an Objective-C class or category. While this option will typically result in a larger executable (due to additional object code loaded into the application), it will allow the successful creation of effective Objective-C static libraries that contain categories on existing classes.

In my case I had to put these flags on the primary application target (the one using the library) rather than the library itself, which strikes me as odd.

Update: You also have to add -all_load in some cases

  Permalink |  Comments[6]


Related Items


Recent Entries

 » How to make the Flip Mino HD import into iMovie 09
 » How to patch Xcode to work with Subversion 1.5
 » iTunes 8 on Windows XP x64
 » iPhone SDK Code Signing Insights
 » Making iPhone Distribution Profiles Show Up


You can skip to the end and leave a response. Pinging is currently not allowed.



6 Responses to “Objective-C static libraries and categories”

  1. Mark Says:

    Great Tip!

  2. geeknurse Says:

    You made my day! :D

  3. taco Says:

    I was having the same problem in SDK 3.0 and adding the flag in the target application did not help. I am going to it in the static library project later today. Hopefully this will fix the \

  4. Duane Fields Says:

    You also have to add -all_load in some cases

  5. Matthias Hennemeyer Says:

    Thank You!
    Two days of debugging and the -all_load flag made it working …

Leave a Reply

 
 

This is a captcha-picture. It is used to prevent mass-access by robots. (see: www.captcha.net)

You must read and type the 5 chars within 0..9 and A..F, and submit the form.

  

Oh no, I cannot read this. Please, generate a