AIX shared libs with g++: global constructors not executed

AIX shared libs with g++: global constructors not executed

Post by Thomas Kemme » Tue, 25 Sep 2001 21:57:17

Hi all,

I'm having some troubles when trying to build shared C++ libraries with
g++ 2.95.2 on AIX 4.3.3;

It seems like if I load a shared library using dlopen(), global/static
constructors in the library are not executed.

From "AIX Linking an Loading Mechanisms" (aix_ll.pdf) I know there
exists a script MakeC++SharedLib which presumably solves this problem
for the IBM VisualAge compiler, but I couldn't find something similar
for g++.

Has anyone successfully managed to create shared libraries with g++, so
that static constructors are invoked properly?



Thomas Kemmer
Hyperwave Software R&D, A-8010 Graz, Albrechtgasse 9/II
Tel: +43-316-820918-611, Fax: +43-316-820918-99


1. Q: constructor not called for global object in solaris shared lib

This smells like an FAQ; but nothing poped up on a search.
 A global object is defined in a file (C++) :

                 Bus tmpbus;

This file is compiled and becomes partof shared library (.so) :

                 CC -c foo.cpp
                 ld -G foo.o

Another object is  linked to this shared library :

                 CC -o a.out main.cpp -L. -lfoo

Now, when we execute a.out, we find that the constructor for the object
tmpbus is not getting called.  If instead of creating a shared library out
of foo.o, it is directly linked with main.o, the contructor is called
properly.  Are we missing anything ?

We are using SUNWsproc C++ ver 4.1 and running solaris 2.x.  I do not
get to read the news group till the end of the day.  So, if you are

Thank you.


2. Configuring Sound Blaster in Linux

3. shared libs and global Constructors

4. Passwords with Netscape Enterprise Server

5. Global constructors in ELF so libs NOT CALLED!

6. Help! Lost all /bin files

7. static constructor from shared library not getting called on aix when loaded by Apache Web Server

8. chat conference program?

9. KDE-Problems on Solaris: Global constructors not called!!

10. Shared libs, C++, static constructor considerations

11. SOLVED: static variable class constructors in shared libs

12. constructor order/shared libs

13. static variable class constructors in shared libs?