This is the mail archive of the cygwin@sources.redhat.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]

global constructors not called in dll


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


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