Re: Problems linking json-framework with ios application
Re: Problems linking json-framework with ios application
- Subject: Re: Problems linking json-framework with ios application
- From: Wim Lewis <email@hidden>
- Date: Tue, 17 May 2011 14:32:33 -0700
On 17 May 2011, at 2:03 PM, Damien Cooke wrote:
> I am building a library to be used by other apps. I have included the json-framework in the library project and used the -ljson flag as directed. Now this all works fine, until my app uses one of the JSON categories that the library implements.
This is a problem with ObjC categories and static libraries. Categories do not involve any linker symbols (they're completely dynamic), and files in a static library only get included in the final binary if they are needed to resolve a linker symbol reference (usually this is a nice feature of static libraries but for ObjC it's a nuisance).
ObjC *classes* can have this problem as well, especially if you're playing tricks like dynamically registering a class with some manager or controller object in the class's +didLoad. Usually the problem shows up with categories, though.
There are a handful of ways to deal with this-
- You can link the static library into a single object file (json.o) and link that to your iOS app
- You can use a linker flag like -all_load or -ObjC to force the categories to be linked
- You can play tricks with defining symbols in the same file as the category implementation and referencing them from any file that relies on that category's existence
The third option allows you to keep the fine-grained loading behavior of static libraries, but it requires you to do a lot of manual maintenance of those symbols; I've never actually found it to be worthwhile.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden