www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/08/07/14:10:15

Xref: news2.mv.net comp.os.msdos.djgpp:6772
From: alaric AT abwillms DOT demon DOT co DOT uk (Alaric B. Williams)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: linking question
Date: Sat, 03 Aug 1996 15:01:35 GMT
Lines: 61
Message-ID: <839084380.8973.2@abwillms.demon.co.uk>
References: <DvHGAq DOT G29 AT ritz DOT mordor DOT com>
NNTP-Posting-Host: abwillms.demon.co.uk
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

macleod AT ritz DOT mordor DOT com (J.J. Pierson ) wrote:

>OK. I was playing around with the gcc compiler and ld linker. I figured 
>I'd try to compile to an object file and then link it separately.

>I compiled like this:

>"gcc -c proto.c"

>I got a proto.o file.

>I then tried:

>"ld proto.o -lc"

>It can't find the file -lc... 

>I then tried:

>"ld proto.o -L d:\djgpp\lib\ -lc"

>It finds the file, but I then get errors such as:

>* d:/djgpp/bin/ld.exe: warning: cannot find entry symbol start; defaulting 
>* to 000010a8
>* 
>* malloc.c(.text+0x1e): undefined reference to `__sbrk'
>*  

You need to link it with a few more things. Like crt0.o (I think
that's what it's called) in the lib directory... I think __sbrk is the
sbrk helper in there. crt0 also contains the entry symbol, which is
the routine that calls main()! Without it, not a lot will happen...

Try somethign like:

ld proto.o d:\djgpp\lib\crt0.o -lc -lgcc

libgcc, I seem to remember, defines a few internal helper functions
the compiler uses invisibly.

>I have no idea why it's not linking correctly, esp. since if I just do 
>"gcc proto.c", it will compile and link fine.

gcc includes those funnies automagically. It uses the /lib/specs file
to decide what to do. There's a prize if you can understand the linker
section :-/ (not really...)


Regards,




ABW
--
I have become... Comfortably numb...

Alaric B. Williams Internet : alaric AT abwillms DOT demon DOT co DOT uk
<A HREF="http://www.hardcafe.co.uk/Alaric/">http://www.hardcafe.co.uk/Alaric/</A>

- Raw text -


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