Constructors in shared libraries on HP/UX
Jeffrey A Law
law@cygnus.com
Fri May 29 14:01:00 GMT 1998
In message < 19980529191635.47746@hera.rbi.informatik.uni-frankfurt.de >you write:
>
> Constructors of global objects in g++-made shared libraries on HP/UX
> are not called if the libraries are loaded dynamically. I experience
> this problem when loading C++ extensions into the Tcl language.
>
> The problem can be solved by using the +I option of the HP/UX linker,
> which arranges for a function to be invoked upon loading the library.
Using the +I is a bad idea as the default behavior. I don't remember
the specifics, but I think it had something to do with when/how the
dtors were run (unload point or program exit).
> Unfortunately, there seems to be no corresponding option for
> destructors when unloading the shared library. Could that be
> done by installing an atexit() handler?
Actually, the same routine is called again, with a different argument
for the dtors.
The recommended way to handle C++ ctors in shared libraries that
you load via shl_load is to write a little wrapper which shl_loads
your library/code, then calls the library's construtor routine.
> BTW, it would also be useful if `g++ -shared' implied the -fPIC
> option, which is needed to compile the collect2-created source code.
I thought at one time there was an argument against, this, but I can't
remember what it was. Does anyone know why this might be a bad idea?
jeff
More information about the Gcc-bugs
mailing list