From: Mumit K. <khan@NanoTech.Wisc.EDU> - 2001-07-24 20:43:11
|
On Tue, 24 Jul 2001, Chris Marshall wrote: > Gang - > > I need to be directed towards the HOW-TO's for mingw. Particularly, the > question I need answered is how do I compile a C program which uses someone > else's DLL that I don't have access to the source code for? I have the .H > file, and I have a .LIB file, and I have the .DLL. How do I put all these > pieces together? > > I've tried: > > gcc -I./inc -L./lib hello_psft.c psmsg.dll This is of course the right thing to do, but since you're linking directly to a DLL (note that this is GNU extension, and, as far as I know, not supported by any of the other compiler vendors on Windows), there are some pitfalls. I believe Danny Smith explained it a while back in a different thread. > And I get all sorts of "undefined reference" messages. I assume that somehow > I've got to tell the compiler to use the vendor supplied DLL, I just don't > know how to do that. If I remember your original problem, the unresolved symbols had '@' in the name, which means that these are functions using stdcall/pascal calling convention. If your DLL exports stdcall symbols, and especially if there is symbol aliasing going on via the export definition file, you really can't link directly to a DLL -- you'll have no choice but to create an import library. Here's a quick test: compile the file hello_psft.c and look at the symbols (pick one that is unresolved after you try to link). $ gcc -c -I./inc hello_psft.c $ nm hello_psft.o | grep <YOUR_SYMBOL_NAME> Now look at the symbols that your DLL exports: $ objdump -p psmsg.dll | less [ Scan for the section "[Ordinal/Name Pointer] Table" and you'll find the list of names ] Now see if there's a match between the two. My suggestion -- create an import library and just use it. I assume you have an import library for some other compiler, and if so, it shouldn't be difficult to create one for GCC. Perhaps easier said than done. Regards, Mumit |