This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

msvc dll and gcc


Bijan Tuysserkani writes:
 > Hi,
 > 
 > I want to use some functions of a dll library in my code
 > that gets compiled with gcc. To test if that works I created
 > a small dll example that works fine under msvc.
 > 
 > Then I created a def file and used 
 > 
 > dlltool --def foo.def --dllname foo.dll --output-lib foo.a
 > 
 > That worked fine. 
 > 
 > But when I link it with together with footest.c, which calls the 
 > dll-function, I get this result :
 > 
 > bash$ gcc footest.c foo.a -o footest.exe
 > C:\TEMP\cc0014041.o(.text+0x2e):footest.c: undefined reference to `myhello'
 > gcc: Internal compiler error: program ld got fatal signal 1
 > 
 > Below are the sources I use :

Your problem is that you are trying to link _myhello (from gcc)
against _myhello@0 (as produced by dlltool). ld doesn't know these are
the same, and there's no reason why it should given that the @n stuff
comes from Microsoft's gratuitous extensions to C to allow callee
disposal of parameters. I believe you can add a line to your .def file
saying

myhello=myhello@0

and that this should help, however, I haven't tried this.

 > -----------------------------------------------------------------
 > foo.c : source file for dll, compiled with msvc4.2
 > 
 > #include "stdio.h"
 > 
 > __declspec(dllexport) void myhello()
 > {
 > 	printf("hello world\n");
 > }
 > -----------------------------------------------------------------
 > footest.c : source for gcc 
 > 
 > #include "stdio.h"
 > 
 > extern void myopinion();
 > 
 > int main()
 > {
 > 	printf("start my dll function\n");
 > 	myopinion();

        ^^^^^^^^^ myhello perhaps

 > 	return(0);
 > }
 > -----------------------------------------------------------------
 > foo.def : 
 > 
 > LIBRARY foo
 > EXPORTS
 > myhello@0
 > 
 > ------------------------------------------------------------------
 > output of nm :
 > bash$ nm foo.a | grep T
 > 00000000 T _myhello@0
 > 
 > 
 > I then downloaded the directX package from  
 > http://dragon.acadiau.ca/~025668b/develop/cygnus
 > but again, when I tried to compile it with 
 > 
 >  gcc main.c libddraw.a -o main.exe
 > 
 > I get this :
 > 
 > C:\TEMP\cc0014301.o(.text+0x72):main.c: undefined reference to
 > `CreateWindowExA@48'
 > C:\TEMP\cc0014301.o(.text+0x88):main.c: undefined reference to `ShowWindow@8'
 > C:\TEMP\cc0014301.o(.text+0x93):main.c: undefined reference to
 > `UpdateWindow@4'
 > C:\TEMP\cc0014301.o(.text+0xa7):main.c: undefined reference to
 > `GetMessageA@16'
 > C:\TEMP\cc0014301.o(.text+0xb9):main.c: undefined reference to
 > `TranslateMessage@4'
 > C:\TEMP\cc0014301.o(.text+0xc2):main.c: undefined reference to
 > `DispatchMessageA@4'
 > C:\TEMP\cc0014301.o(.text+0x22c):main.c: undefined reference to
 > `GetStockObject@4'
 > C:\TEMP\cc0014301.o(.text+0x241):main.c: undefined reference to
 > `RegisterClassA@4'
 > C:\TEMP\cc0014301.o(.text+0x289):main.c: undefined reference to `BeginPaint@8'
 > C:\TEMP\cc0014301.o(.text+0x29b):main.c: undefined reference to `EndPaint@8'
 > C:\TEMP\cc0014301.o(.text+0x2a5):main.c: undefined reference to
 > `PostQuitMessage@4'
 > C:\TEMP\cc0014301.o(.text+0x2bd):main.c: undefined reference to
 > `DefWindowProcA@16'
 > gcc: Internal compiler error: program ld got fatal signal 1
 > 
 > output of nm :
 > 
 > bash$ nm libddraw.a | grep T
 > 00000000 ? ___imp_thk3216_ThunkData32
 > 00000000 T _thk3216_ThunkData32
 > 00000000 ? ___imp_thk1632_ThunkData32
 > 00000000 T _thk1632_ThunkData32
 > 00000000 T _VidMemLargestFree
 > 00000000 T _VidMemInit
 > 00000000 T _VidMemFree
 > 00000000 T _VidMemFini
 > 00000000 T _VidMemAmountFree
 > 00000000 T _VidMemAlloc
 > 00000000 T _InternalUnlock
 > 00000000 T _InternalLock
 > 00000000 T _DllGetClassObject
 > 00000000 T _DllCanUnloadNow
 > 00000000 T _DirectDrawEnumerateW
 > 00000000 T _DirectDrawEnumerateA
 > 00000000 T _DirectDrawCreateClipper
 > 00000000 T _DirectDrawCreate
 > 00000000 T _DSoundHelp
 > 00000000 T _DDInternalUnlock
 > 00000000 T _DDInternalLock
 > 00000000 T _DDHAL32_VidMemFree
 > 00000000 T _DDHAL32_VidMemAlloc
 > 
 > Does anybody know why the linker cannot find the symbols?
 > 
 > thanks in advance,
 > 
 > 	Bijan
 >                                                           /\
 >                                                   .  /\  /  \
 > ------------------------------------------------ / \/  \/    \
 > Bijan Tuysserkani                               /      /      \
 > Qualcomm Inc.                                                  \
 > 5450 Western Ave.                             
 > Boulder, CO  80301                        (303) 473-6852 (voice)
 > btuysser@qualcomm.com                     (303) 473-6665 (fax)
 > 
 > -
 > For help on using this list (especially unsubscribing), send a message to
 > "gnu-win32-request@cygnus.com" with one line of text: "help".
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]