Mail Archives: cygwin/2002/08/15/19:53:56
I have scoured the web and the mailing lists to no avail. How do I
build a DLL to dynamically run with a non-cygwin application?
Background:
A vendor has supplied a program that links to a DLL at runtime to do
stuff. I wish to write a DLL that this program may use.
Here is some psuedocode from my DLL:
long foo (<some params>) {
/* do some bit manipulations */
}
I can build this fine using the ld/dlltool/ld/dlltool/ld trick. This
also works if I just use the -shared flag to ld.
The vendor's program, which I'll just call 'V', happily accepts it. At
runtime, V has a parameter that specifies the DLL (i.e., my DLL must be
relocatable). Everything works as expected.
Now, suppose that I want to add some debugging info to my DLL, like so:
#include <stdio.h>
long foo (<some params>) {
printf ("Entering foo.\n");
/* do some stuff */
}
Compiling with ld fails because of the unresolved symbol printf(). I
can make this error go away by adding a '-lc' flag to the end of ld.
The DLL now compiles and builds.
When I now run it under V, I get the application error:
The instruction at "0x77f6ce4c" referenced memory at "0x00000010".
The memory could not be "written".
This seems to imply that linking to libc alters the DLL fundamentally.
I have tried the following:
- Try compiling with -mno-cygwin. I find that I still need the '-lc'
flag, and the application error still occurs.
- Remove the printf() call by leave '-lc'. Although V works, I really
do want the debugging data.
- Try changing the entry point with '-e
__cygwin_noncygwin_dll_entry AT 12'. Apparantly this tricked worked
with an older release of cygwin, but not anymore.
The closest reference I have found is Mumit Khan's comment "if you're
loading these from non-Cygwin application, eg., from an MSVC
application..." at
http://www.xraylith.wisc.edu/~khan/software/gnu-win32/dllhelpers.html.
I tried this (bullet #3 above) but it no longer works.
This is all with the latest stable release of the cygwin tools.
Hopefully somebody here has insight on how to do this deceptively easy
task.
--
Jason Tang / tang AT jtang DOT org / http://www.jtang.org/~tang
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
- Raw text -