views:

286

answers:

1

I have a static library (let's call it S) that uses a category (NSData+Base64 from MGTwitterEngine) and a C library (MiniZip wrapped by ZipArchive, a mm file).

This static library is used in an iPhone 3.x project (let's call it A). To be able to use the MiniZip library I included its files in project A as well as the static library S. If not I get compilation errors.

Project A works fine on the simulator. When I run it on the device, I get unrecognized selector errors when the category is used.

As pointed out here, it seems there's a linker bug that affects categories in iPhone 3.x (http://stackoverflow.com/questions/1147676/categories-in-static-library-for-iphone-device-3-0). The workaround is to add -all_load to the Other Linker Flags of the project that references the static library.

However, if I do this then I get duplicate symbol errors because I included the MiniZip libraries in project A.

A workaround is to include the category files in project A as well. If I do this, project A works well in the device, but fails to build on the simulator because of duplicate symbol errors.

How should I set up project A to make it work on the simulator and the device with the same configuration?

+2  A: 

Instead of -all_load you could try to use -ObjC which should make the linker aware of Objective-C categories without loading all symbols (in some cases this works for me, in others it doesn't).

Another workaround would be not to include the MiniZip library into your project (A), but only the header files (which are the only files needed to correctly compile your project). The linker will then use the MiniZip library which was linked to your static library.

frenetisch applaudierend
Thanks! I was using -ObjC before and it doesn't work. As far as I understand, this is the bug in the iPhone 3.x linker. -ObjC is not enough to make the linker aware of all categories. Concerning the second workaround, if I don't include MiniZip implementation files in project A I get a symbol not found error for "_OBJC_CLASS_$_ZipArchive". ZipArchive is the mm wrapper. However, if I just include ZipArchive.mm and the header files, it works both on the simulator and the device. I will wait a bit more to see if someone else has a simpler solution, and if not I'll choose your answer.
hgpc
Thanks, I wasn't aware of this bug, this makes things a bit clearer for me too.
frenetisch applaudierend