Subject: Re: helpful hints to build dlls in Win32 using cygwin (gnu)
From: [email-masked] (Fergus Henderson)

31 Jul 1997 23:18:32 -0700
Sender: [email-masked]
Approved: [email-masked]
Distribution: cygnus
Message-ID: <[email-masked]>
References: <[email-masked]>
Original-To: [email-masked]
Original-Sender: [email-masked]

Padmakar Vishnubhatt <[email-masked]> 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@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 <[email-masked]>   |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>   |  of excellence is a lethal habit"
PGP: finger [email-masked]         |     -- the last words of T. S. Garp.
-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".