delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2000/09/13/06:03:41

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT sources DOT redhat DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT sources DOT redhat DOT com>
List-Help: <mailto:cygwin-help AT sources DOT redhat DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT sources DOT redhat DOT com
Delivered-To: mailing list cygwin AT sources DOT redhat DOT com
Message-ID: <39BF5086.CB77744A@e-14.com>
Date: Wed, 13 Sep 2000 11:01:42 +0100
From: Nigel Wetten <nwetten AT e-14 DOT com>
X-Mailer: Mozilla 4.72 [en] (WinNT; I)
X-Accept-Language: en
MIME-Version: 1.0
To: cygwin AT sourceware DOT cygnus DOT com
Subject: 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 AT 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 AT 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 AT 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 AT 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 AT sourceware DOT cygnus DOT com

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019