Mail Archives: cygwin/1997/07/31/23:18:32
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 -