delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1997/07/18/10:25:37

From: jont AT harlequin DOT co DOT uk (Jon Thackray)
Subject: msvc dll and gcc
18 Jul 1997 10:25:37 -0700 :
Approved: cygnus DOT gnu-win32 AT cygnus DOT com
Distribution: cygnus
Message-ID: <199707180939.KAA24738.cygnus.gnu-win32@zaphod.long.harlequin.co.uk>
References: <3 DOT 0 DOT 1 DOT 32 DOT 19970717174505 DOT 009791b0 AT smtphost-co DOT qualcomm DOT com>
Original-To: "gnu-win32 AT cygnus DOT com" <gnu-win32 AT cygnus DOT com>
In-Reply-To: <3.0.1.32.19970717174505.009791b0@smtphost-co.qualcomm.com>
Original-Sender: owner-gnu-win32 AT cygnus DOT com

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 AT 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 AT 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 AT 0
 > 
 > ------------------------------------------------------------------
 > output of nm :
 > bash$ nm foo.a | grep T
 > 00000000 T _myhello AT 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 AT 48'
 > C:\TEMP\cc0014301.o(.text+0x88):main.c: undefined reference to `ShowWindow AT 8'
 > C:\TEMP\cc0014301.o(.text+0x93):main.c: undefined reference to
 > `UpdateWindow AT 4'
 > C:\TEMP\cc0014301.o(.text+0xa7):main.c: undefined reference to
 > `GetMessageA AT 16'
 > C:\TEMP\cc0014301.o(.text+0xb9):main.c: undefined reference to
 > `TranslateMessage AT 4'
 > C:\TEMP\cc0014301.o(.text+0xc2):main.c: undefined reference to
 > `DispatchMessageA AT 4'
 > C:\TEMP\cc0014301.o(.text+0x22c):main.c: undefined reference to
 > `GetStockObject AT 4'
 > C:\TEMP\cc0014301.o(.text+0x241):main.c: undefined reference to
 > `RegisterClassA AT 4'
 > C:\TEMP\cc0014301.o(.text+0x289):main.c: undefined reference to `BeginPaint AT 8'
 > C:\TEMP\cc0014301.o(.text+0x29b):main.c: undefined reference to `EndPaint AT 8'
 > C:\TEMP\cc0014301.o(.text+0x2a5):main.c: undefined reference to
 > `PostQuitMessage AT 4'
 > C:\TEMP\cc0014301.o(.text+0x2bd):main.c: undefined reference to
 > `DefWindowProcA AT 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 AT qualcomm DOT com                     (303) 473-6665 (fax)
 > 
 > -
 > 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".
-
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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019