I known this is an old topic, but today I found out a new way that some developers devised to avoid it.
Long story short: the linker tool that Apple provides messes it up when linking a static library containing categories. A pair of linker flags (-ObjC -all_load) has to be provided in order to work around it. The flags instruct the linker to load all the methods (even the ones not being used by that particular application) and collides with some other libraries issuing duplicate symbols errors.
The solution from Apple’s point of view seems to be tricky as it is not being fixed for a long time now, and many developers had opted in for less intrusive fixes (like using the less restrictive -force-load setting) but still requires a big deal of internal knowledge of the tool chain internals.
I read this morning on RestKit development list a new way to deal with it I wasn’t aware of. The original fix was supplied by the developers of the well-known library Three20.
The fix consists in tricking the linker into thinking that the library indeed has some (dummy) implementation code worth using by using the following #define statement:
#define FIX_CATEGORY_BUG(name) @interface FIXCATEGORYBUG ## name; @end @implementation FIXCATEGORYBUG ## name; @end
They way you apply the code to an existing class category implementation file is like this:
FIX_CATEGORY_BUG(NSData_MD5) @implementation NSData (MD5)
By using this technique you are not required anymore to use -all-load linker flag, and you won’t get all those annoying errors when linking more than one static library.
References:
Apple Technical Q&A article
Three20 fix
RestKit fix