* global constructors not called in dll
@ 2000-09-13 3:02 Nigel Wetten
0 siblings, 0 replies; only message in thread
From: Nigel Wetten @ 2000-09-13 3:02 UTC (permalink / raw)
To: cygwin
Hello all,
I'm having trouble with dll's I've built not having their C++ global
constructors executed. I'm guessing this is why using iostreams within
the dll code causes a crash.
Have I done something wrong in my build process? I can build dlls that
work, provided they not use global constructors (or iostreams).
I searched the list archive, but couldn't find anything recent enough to
be of help. I can't be the only person to run into this...
I'm building according to the instructions in the user manual on the web
site, with the addition of a -shared flag(I kept getting unresolved
references to WinMain@16 otherwise)
I've also tried using dllwrap and with _cygwin_dll_entry() returning 1,
but the result is the same.
I tried passing -Ur to ld, instead of using -shared, but that caused ld
to seg fault. If I pass -Ur only on the final link for the main
executable, the binary hangs before it gets to main().
The program below prints hello only once, rather than twice.
Nigel
=========================================================================
Build commands:
g++ -c main.cc
g++ -c mydll.cc
g++ -s -Wl,--base-file,mydll.base -o mydll.dll mydll.o -shared
-Wl,-e,_mydll_init@12
dlltool --base-file mydll.base --def mydll.def --output-exp mydll.exp
--dllname mydll.dll
g++ -s -Wl,--base-file,mydll.base,mydll.exp -o mydll.dll mydll.o
-shared -Wl,-e,_mydll_init@12
dlltool --base-file mydll.base --def mydll.def --output-exp mydll.exp
--dllname mydll.dll
g++ -Wl,mydll.exp -o mydll.dll mydll.o -shared -Wl,-e,_mydll_init@12
dlltool --def mydll.def --dllname mydll.dll --output-lib mydll.a
g++ main.o mydll.a
=======================================================================
main.cc
extern "C" void print();
int main()
{
print();
}
========================================================================
mydll.cc
#include <cstdio>
class myClass {
public:
myClass();
};
myClass::myClass()
{
printf("hello\n");
}
myClass global;
extern "C" {
void print()
{
myClass local;
}
}
#include <windows.h>
extern "C" {
int WINAPI
mydll_init(HANDLE h, DWORD reason, void *foo)
{
return 1;
}
}
--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2000-09-13 3:02 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-09-13 3:02 global constructors not called in dll Nigel Wetten
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).