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: Thu, 6 Apr 2006 12:08:50 -0700
- Thread-topic: dlopen() on 10.3 and static initializers
No luck :( The printf in my _init() is not showing up, and I'm not
seeing any of the static initializers either.
My next attempt would be to convert the libs to be bundles, but perhaps
I'm missing something simple.
I first changed the MACH_O_TYPE to MH_BUNDLE, but then found that I had
to change lots of other settings like unsetting compat version (both
project and target), current version (same) and now it's complaining it
can't link with single-module.
I've set none of these myself, apparently they were all set when I chose
the dynamic library template. It's a bit hard to find how to unset them
properly, and I'm beginning to think I'm going about this the wrong way.
I don't want to rebuild all the projects (there are a number of them) is
there a better way?
Dave
-----Original Message-----
From: David Litwin
To: Peter O'Gorman
Cc: Xcode Users
Subject: RE: 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:
.com
This email sent to email@hidden
_______________________________________________
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