delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1997/07/31/23:18:32

From: fjh AT cs DOT mu DOT OZ DOT AU (Fergus Henderson)
Subject: Re: helpful hints to build dlls in Win32 using cygwin (gnu)
31 Jul 1997 23:18:32 -0700 :
Sender: mail AT cygnus DOT com
Approved: cygnus DOT gnu-win32 AT cygnus DOT com
Distribution: cygnus
Message-ID: <199708010456.OAA10715.cygnus.gnu-win32@mundook.cs.mu.OZ.AU>
References: <33E0F327 DOT DF8B81B3 AT Eng DOT Sun DOT COM>
Original-To: gnu-win32 AT cygnus DOT com
Original-Sender: owner-gnu-win32 AT cygnus DOT com

Padmakar Vishnubhatt <padmakar AT eng DOT sun DOT com> writes:

>I did exactly as u recommended in your hints - and yet I get the
>following error when I run the linker (ld).  Am I missing something in
>the cygwin distribution?
>
>/gnuwin32/b18/H-i386-cygwin32/i386-cygwin32/lib/libcygwin.a(libccrt0.o)(.text+0x
>8a):libccrt0.cc: undefined reference to `GetModuleHandleA AT 4'

Your problem is due to `_impure_ptr'.  (By the way, to debug these
sorts of problems, use the `-Map' and `--cref' options to `ld'.)
libccrt0.o should not be linked in to DLLs at all.
The reason that it does get linked in is because it defines `_impure_ptr',
which is referenced by your code (implicitly, e.g. because stdout
is #defined as `_impure_ptr._stdout'), and which is
not defined anywhere else.

You need to provide a definition of `_impure_ptr'.
You also need to initialize it (otherwise references to stdout
etc. in your DLL will be bogus).

For example:

	/* impure.c -- link this into your libfoo.dll */
	void *_impure_ptr;
	void *libfoo_impure_ptr_ptr = &_impure_ptr_ptr;

	/* main.c -- link this into the program that uses the DLL */
	int main() {
		(*_imp_libfoo_impure_ptr_ptr) = _impure_ptr_ptr;
		...
	}

No doubt this is fairly confusing.

I am currently in the process of getting Mercury to use DLLs
on gnu-win32.  I have packaged up a neat solution to the problem
of global variables in DLLs.  See <http://www.cs.mu.oz.au/~fjh/gnu-win32>.

I also have a solution to this problem with `_impure_ptr',
but it's not yet on my WWW page (I'm still testing it).

--
Fergus Henderson <fjh AT cs DOT mu DOT oz DOT au>   |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>   |  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".

- Raw text -


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