RE: dlopen() on 10.3 and static initializers
RE: dlopen() on 10.3 and static initializers
- Subject: RE: dlopen() on 10.3 and static initializers
- From: "David Litwin" <email@hidden>
- Date: Wed, 5 Apr 2006 19:42:43 -0700
- Thread-topic: dlopen() on 10.3 and static initializers
These are dynamic shared libraries, and have the TWOLEVEL flag set when
I run otool -hv.
I noticed a "-Wl,-single_module" on my link line so I believe that to be
already correct, perhaps because I have the LIBRARY_STYLE set to
DYNAMIC.
I'll give the _init trick a try.
Thanks,
David Litwin
BigFix
-----Original Message-----
From: Peter O'Gorman [mailto:email@hidden]
On Wed, 2006-04-05 at 19:12 -0700, David Litwin wrote:
> I'm in the process of qualifying my app on 10.3.
>
>
> My app uses dlopen() to load some libraries, which contain a number of
> static objects that register themselves to the app in their
> constructors.
>
> While this works fine in 10.4, on 10.3 these registrations never
> occur. There are no errors loading the libraries, but it seems that
> no C++ static object constructors are being called.
>
Are you dlopening dynamic shared libraries or bundles? On 10.3 static
constructors were more likely to be called for MH_BUNDLE than MH_DYLIB.
If they are dynamic shared libraries and you can not change that, are
they two level namespace or flat namespace? (hint otool -hv).
If twolevel, try adding this to each library:
void _init(void);
void _init() {;}
And ensure that you link your libraries with -single_module.
dlcompat's dlopen will look up and call _init for each library it
explicitly dlopens, and if the library is linked single_module, all the
module's static initializers will be called at that time.
On 10.4 the dynamic linker was rewritten to work better and dlopen()
became part of the dynamic linker, not an external function that used
dyld.
Hope this helps,
Peter
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden