This is the mail archive of the
mailing list for the GCC project.
Re: Apache module in C++
- To: Alexandre Oliva <aoliva at redhat dot com>
- Subject: Re: Apache module in C++
- From: Jes Rahbek Klinke <jrk at sysorb dot com>
- Date: Thu, 02 Aug 2001 10:21:39 +0200
- Cc: gcc at gcc dot gnu dot org
- Organization: SysOrb
- References: <3B333E48.18AEDC98@sysorb.com> <email@example.com>
- Reply-To: sysorb at sysorb dot com
Alexandre Oliva wrote:
> On Jun 22, 2001, Jes Rahbek Klinke <firstname.lastname@example.org> wrote:
> > My problem is, that contructors and destructors of global variables is
> > not called, as the main apache executable is not aware of C++.
> > Does anyone know if collect2 can do this, and how?
> Presumably, linking your C++ shared library using g++, which already
> uses collect2, should get initializers to run when your module is
> dlopen()ed, and global destructors to run when it's dlclose()d (but
> beware static variables in function scope; these are scheduled for
> destruction with atexit(), so they'll only run when the whole
> application terminates, which may be long after the module is
> If a module created with g++ won't have initializers run at dlopen()
> time, odds are that the OS you're running doesn't support this
> feature. Fortunately, such OSs are rare these days.
You are absolutely right, if I compile with the command
$ g++ -g -fPIC -c foo.cc
and link with
$ g++ -shared -fPIC -o mod_foo.so foo.cc
all the global construtors will be called when the module is loaded by
The only problem was for me to realize, that there was no problem at all.