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]

Re: [Help] Undefined referece to fopen and other Stdlib functions when compileing a dll


When using ld.exe directly, instead of using the compiler
driver gcc.exe you must specify all of the libraries you
want to link into the application, like this

-lkernel32 -luser32 -lgdi32

you must also tell the linker where to find these libraries
like this

-L/my/lib/dir

It's usually much easier to let gcc link in the appropriate
libraries, by using 

gcc -mwindows

when you are ready to link, although -m anything is a bad
name for a gcc option, because it's reserved for processor
options by the specs file, but that's what cygnus did.<sigh>

the quickest way that I know of to find out what libraries are
needed is to cd into the directory where your libraries are,
typically .../H-i386-cygwin32/i386-cygwin32/lib
and do 

grep -l functionname *

small (L)         functionname without the @16 on the end
do that for 2 or three of the functions that are showing
up as not found, and then relink with whichever libraries
contain the function.

also on your link line below you need to use 

--dll -e _DllMain@12 (or whatever your dll init function is)

On Sun, 20 Jul 1997 18:21:54 -0700 (PDT), you wrote:

>
>Hi Folks,
>I have been using GCC for some time now.  I have never had any problems with Gcc Cygwin
> until I tired to compile some source code that was developed using MSVC++4.0.
> 
> The source code is a Dll.
> 
> When I create and compile my own Dlls using Cygwin I have no problems.  However now that I
> am trying to compile the MSVC++ code I am gettion all sorts of undefined references to
> standard lib files.
> 
> 
> I have a pentium 32MB RAM.
> Cygwin vew b18 and have the Unix utils setup.
> Windows95
> 
> 
>  The source code does compile. I do get my object files.  It is durint like time that I get
> my errors.
> 
> I am not using a make file, but I am using a Bash srcipt to compile my dll.  The script is
> small and looks like this
> 
> *******----------------------------------**********************
> #!/bin/sh
> 
> INCLUDE="/Gator/Test/IOTEST~1/GCC-DLLs/Include"
> 
> gcc -c commio.c -I $INCLUDE
> 
> gcc -c timer.c -I $INCLUDE
> 
>  echo EXPORTS > commioB.def
> 
> 
>  nm commio.o timer.o | grep '^........ [T] _' | sed 's/[^_]*_//' >>         commioB.def
> 
> dlltool --def commioB.def --output-exp commio.exp --output-lib commio.a --dllnam
> e commio.dll
> 
> ld -o commio.dll commio.exp commio.o timer.o
> 
> *******----------------------------------**********************
> 
> As I said eariler, the code did compile, but during link time I got this errors
> 
> commio.o(.text+0x885):commio.c: undefined reference to `fprintf'
> commio.o(.text+0x897):commio.c: undefined reference to `fclose'
> commio.o(.text+0x91e):commio.c: undefined reference to `fopen'
> commio.o(.text+0x92d):commio.c: undefined reference to `Sleep@4'
> commio.o(.text+0x93d):commio.c: undefined reference to `GetCommState@8'
> commio.o(.text+0x95b):commio.c: undefined reference to `SetCommState@8'
> commio.o(.text+0x96a):commio.c: undefined reference to `GetCommProperties@8'
> commio.o(.text+0x97d):commio.c: undefined reference to `ClearCommError@12'
> commio.o(.text+0x99a):commio.c: undefined reference to `OutputDebugStringA@4'
> commio.o(.text+0x9bb):commio.c: undefined reference to `WriteFile@20'
> commio.o(.text+0x9f1):commio.c: undefined reference to `fprintf'
> commio.o(.text+0xa28):commio.c: undefined reference to `fprintf'
> commio.o(.text+0xa3e):commio.c: undefined reference to `fprintf'
> commio.o(.text+0xa50):commio.c: undefined reference to `fclose'
> commio.o(.text+0xa92):commio.c: undefined reference to `fopen'
>
> There are alot more, I just wanted to give a sample.
> 
> It looks to me like the code I not linking to the libaries, but I do not know enough
> about Cygwin to find out exactly what libs are linked or not.
> 
> 
> Thanks in advanced
> -- 
>-- 
>______________________________________________________________________________
> Xavier Plasencia                  | 
> San Diego State University        |   Internet    : plasenci@rohan.sdsu.edu
>______________________________________________________________________________
>
>
>-
>For help on using this list (especially unsubscribing), send a message to
>"gnu-win32-request@cygnus.com" with one line of text: "help".
>

(*jeffdb@netzone.nospam.com)
Remove *&.nospam from the above to reply
         Mikey
-
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]