Apache module in C++

Jes Rahbek Klinke jrk@sysorb.com
Thu Aug 2 01:24:00 GMT 2001


Alexandre Oliva wrote:

> On Jun 22, 2001, Jes Rahbek Klinke <jrk@sysorb.com> 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
> dlclose()d)
>
> 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
apache.
The only problem was for me to realize, that there was no problem at all.

Thanks
Jes




More information about the Gcc mailing list