views:

1394

answers:

4

I have categories in my static library. Any application developer should set -ObjC flag to "Other Linker Flags" to use my static library properly. It works fine for iPhone device/iPhone Simulator 2.x and iPhone Simulator 3.0. But it crashes for iPhone device 3.0. As written in this article it is new linker bug. They suggest to use one more linker flag: -all_load. But when I add this flag, build fails too, because there are duplicate symbols.

How to use categories in static libraries for iPhone device 3.0? Any suggestions?

+5  A: 

We ran into the same problem (under 3.0, -ObjC no longer links in categories) within the Core Plot framework. All I can say is that for us, we were able to add the -all_load option to the Other Linker Flags within the target application and that did away with the runtime errors. We didn't see any warnings for duplicate symbols.

I've filed a bug report for the linker behavior, as I'm sure others have.

Brad Larson
A: 

When you add -all_load to your other linker flags, make sure, all frameworks, the library uses are linked with your target app. Otherwise, it will fail to compile. In my case, I had a Category for MKMapView and did not bind the MapKit Framework with my target app, thus the class which the category belongs to wasn't found at build time.

aldi
A: 

I ran into the same "duplicate symbols" problem. Without the -all_load flag, we had to also include all libraries our library linked against in the app link line. Removing these from the app link line solved the issue.

Kenny Leung
A: 

Its a bug caused by trying to fix another bug with a hack. The -all_load fix for the category bug is a total hack. http://blog.binaryfinery.com/?p=225

jamie