This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: Global constructors in DLL ?


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".


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]