From: fjh AT cs DOT mu DOT OZ DOT AU (Fergus Henderson) Subject: Re: DLL Problem 25 Aug 1997 16:48:47 -0700 Approved: cygnus DOT gnu-win32 AT cygnus DOT com Distribution: cygnus Message-ID: <199708250613.QAA27153.cygnus.gnu-win32@murlibobo.cs.mu.OZ.AU> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Original-To: geier AT forwiss DOT uni-passau DOT de (Roland Geier) Original-Cc: gnu-win32 AT cygnus DOT com (Cygnus GNU-win32 mailing list) In-Reply-To: <199708212048.WAA07599@bombadill.forwiss.uni-passau.de> from Roland Geier at "Aug 21, 97 10:48:23 pm" X-Mailer: ELM [version 2.4ME+ PL15 (25)] Original-Sender: owner-gnu-win32 AT cygnus DOT com Roland Geier wrote: > [someone wrote:] > > I'm trying to port a tcl module from unix to win95 as a dll to load within > > wish. .... > > ext+0x15):libcmain.cc: undefined reference to `GetCommandLineA AT 0' > > c:/gnuwin32/b18/H-i386-cygwin32/i386-cygwin32/lib/libcygwin.a(libcmain.o)(.t > > > > ext+0x1e):libcmain.cc: undefined reference to `WinMain AT 16' > > > > This seems to be a reentrancy problem, since a simple call like : > > fprintf(stderr, ...) > > ...for me this seems to be a forgotten '-lkernel32' at link-time :). The > undefined ref to 'WinMain' can be avoided with: > > echo 'int main() { return 0; }' > fixup.c; > echo 'asm (".section .idata$3\n" ".long 0,0,0,0,0,0,0,0");' >> fixup.c; > gcc -c fixup.c > # link fixup.o with your dll... Defining main() will supress the link error, but it will not actually fix the problem. The startup file (crt0.o, I think) containing a definition of `_impure_ptr' will be linked in, but _impure_ptr will not be initialized. This means that any reference to global variables such as `stdout' or `stderr' from within your DLL will be broken, and so your DLL will probably crash. To avoid the problem, you need to initialize your DLL's _impure_ptr from the main program. See for an example of how to do this. -- Fergus Henderson | "I have always known that the pursuit WWW: | of excellence is a lethal habit" PGP: finger fjh AT 128 DOT 250 DOT 37 DOT 3 | -- the last words of T. S. Garp. - For help on using this list (especially unsubscribing), send a message to "gnu-win32-request AT cygnus DOT com" with one line of text: "help".