helpful hints to build dlls in Win32 using cygwin (gnu)
Fergus Henderson
fjh@cs.mu.OZ.AU
Thu Jul 31 22:14:00 GMT 1997
Padmakar Vishnubhatt <padmakar@eng.sun.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@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@cs.mu.oz.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@128.250.37.3 | -- the last words of T. S. Garp.
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".
More information about the Cygwin
mailing list