Global constructors in DLL ?

Colin Peters colin@fu.is.saga-u.ac.jp
Tue Aug 11 18:02:00 GMT 1998


Edwin Essenius <edwin@bitbybit-is.nl> wrote:

>I am using cywin B19.2, with the sergey patches an trying to build a
>C++ DLL. Except for the Global constructors all seems to work.
>Global variables in the DLL are initialized, but the global constructors
>are not called when it is declared in a DLL.


If you have written or obtained your own startup code for the DLL (what the
entry point is set to on the link line, or DllMain possibly) then you should
check that you are calling __main in the startup code on DLL_PROCESS_ATTACH.
__do_global_dtors should be called on DLL_PROCESS_DETACH. Also make sure to
disable atexit inside the DLL (mainly for the call to __main) or the main
process may attempt to call your destructors when it exits, which could be
after the DLL has been detached.

See the file dllcrt1.c in the Mingw32 snapshot on my homepage
(www.geocities.com/Tokyo/Towers/6162/gcc.html) for an example of how this
can be done (Note: this doesn't initialize the cygwin library though).

Colin.

P.S. Apologies for being terse.


-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".



More information about the Cygwin mailing list