Static constructors in dylibs
Static constructors in dylibs
- Subject: Static constructors in dylibs
- From: Randy Croucher <email@hidden>
- Date: Wed, 25 Feb 2004 17:21:27 -0800
I have a dylib with a static constructor in it:
static MyCoolClass f_mycoolclass;
When I load this dylib via NSAddImage, the constructor is not called.
It does no get called until I actually get a function pointer out of
the dylib. I don't load any functions out of this lib. This line of
thinking kind of makes sense for most cases. Who cares if your
constructors get called if you are never going to call anything in the
dylib anyway right?
The problem is that this constructor sets up state variables in yet
another dylib by making calls into it. My dylib and the app itself
both link to this mutual dylib. The app then calls into this mutual
dylib, and the state variables have not been set up.
Is there a way to force these static constructors to be initialized at
load time? These are plugins that do not necessarily have an exported
function that I can get ahold of.
I tried -bind_at_load, but that apparently only works for applications.
I got the following linker error.
/usr/bin/libtool: unknown option character `b' in: -bind_at_load
Randy
_______________________________________________
xcode-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/xcode-users
Do not post admin requests to the list. They will be ignored.