Libraries and glocal constructors

H.J. Lu
Fri Apr 24 16:23:00 GMT 1998

> I've written a simulation library on top of PVM in C++ which I'm compiling
> with EGCS 1.0.2.  The library has bindings for C, C++, FORTRAN, and Ada.
> I intentionally stayed away from declaring any static global objects
> which would need global constructors so that they library could be linked
> with a non-C++ compiler.  I am using standard library classes string,
> ifstream, ofstream, and various STL containers.  Any global objects are
> new'd and accessed via a pointer.
> Are there any global objects in the standard library which would still
> require a global constructor/destructor which would not get initialized
> properly when linked with a non-C++ compiler?
> Is this addressed by the standard?  Is it library implementation dependent?

It is up to the library implementors to do it right. As for Linux and
maybe all ELF-based systems like Solaris, you don't have to worry about
the global constructors in the C++ libraries. They are handled by
ELF and gcc. You can link them against any languages you want. The
ELF and the gcc driver will make sure they do the right thing. My
ELF paper

explains how it is done.

H.J. Lu (

More information about the Gcc mailing list