ObjC runtime and the loader
ObjC runtime and the loader
- Subject: ObjC runtime and the loader
- From: Chandrasekhar Ramakrishnan <email@hidden>
- Date: Wed, 21 Feb 2007 20:50:02 +0100
Hi there. I have a question concerning the interaction between the
ObjC runtime, C++, and the loader. Please let me know if there is a
more appropriate place to ask (Xcode-dev?).
Here is the situtation: I have implemented a thread-safe logger for
use in real-time contexts (i.e., it takes no locks). That's
implemented in C++ and exported via a C interface. The logger class
is a singleton and clients use the global instance for their logging
needs.
I use this logger in my ObjC code and have added a category to
NSObject so that all objects can be logged via my logger:
@interface NSObject (ZKMORLogging)
- (void)logAtLevel:(unsigned)level source:(unsigned)source indent:
(unsigned)indent tag:(NSString *)tag;
- (void)logAtLevel:(unsigned)level source:(unsigned)source indent:
(unsigned)indent;
- (void)logDebug;
@end
I'm using this ObjC code in an app as well as in a plug-in. The app
can work independently of the plug-in and the plug-in can work in
other apps. I've noticed that if I include the code directly in my
app as well as in the plugin (as opposed to making it a framework),
the definition of the ZKMORLogging category in the plug-in overrides
the one in my app. The problem with that is that the code in the plug-
in refers to a different copy of my "global" logger than the one in
my app. Doh!
The solutions I've come up with are:
- Make the shared code a Framework and put it in /Library/Frameworks.
- Make the shared code a Framework and give it the install location:
@loader_path/../Frameworks. The FW can then be put into the private
frameworks directory of the app as well as the plug-in.
- Use the pre-processor to add distinct prefixes to the above method
selectors in the app and the plug-in.
I'm using is the second solution because I don't like installers
(it's actually what I wanted to do to begin with, but I was
previously only aware of @executable_path and just learned about
@loader_path...). But I'd like to know if there are other solutions
to consider. Also, does anyone know of a way to force the global to
be shared between the plugin and the app? I tried fiddling with the
new gcc 4.0 visibility options, but to no avail.
Thanks for any help!
- sekhar
--
C. Ramakrishnan
Illposed Software http://www.illposed.com
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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