Page 1 of 1

using GNU AR to create libraries *.a

Posted: Mon Apr 25, 2005 6:54 am
by distantvoices
Hi folks!

AFter having had quite a desperate search session with the forum search tool, I feel smitten and helpless (no not really, I have found some dox about GNU AR in I-Net as google is a good friend), but what I ask for is just a short collection of
hints:

How to build a library *.a with ar? is it something in the wake of "ar -M scanf.o printf.o malloc.o console.o syscall.o lib.a"

How to link agains such a library? Maybe "ld -L link.ld crt0.o myprog.o -l lib.a myprog.bin"?

thanks for your help!

Re:using GNU AR to create libraries *.a

Posted: Mon Apr 25, 2005 7:07 am
by Candy
both: almost

Code: Select all


ar -rcs bla.a *.o

ld -o totalfile.elf *.o bla.a

all iirc, ar command was checked with manpage

Re:using GNU AR to create libraries *.a

Posted: Mon Apr 25, 2005 7:14 am
by distantvoices
and ld knows just to take the object files it *needs* from that *.a file? I have read something about "incremental linking" which seemed to say: link just the fobject files in which we actually need.

Thanks for reply!

Re:using GNU AR to create libraries *.a

Posted: Mon Apr 25, 2005 9:14 am
by Candy
beyond infinity wrote: and ld knows just to take the object files it *needs* from that *.a file? I have read something about "incremental linking" which seemed to say: link just the fobject files in which we actually need.

Thanks for reply!
Well, no... not entirely

The -s switch to ar tells it to build a symbol-object cross reference table in the .a file. That way, ld knows which objects to take for those symbols and which to leave behind. Incremental linking is just a way to make command lines and link times shorter, by not offering the linker a load of files "you figure it out" but by grouping them logically. That way, it can make smaller symbol tables and use locality at multiple levels.

Re:using GNU AR to create libraries *.a

Posted: Tue Apr 26, 2005 1:23 am
by distantvoices
Ah, that clears it up.

thanks, the ar-stuff works like a charm.

@Solar or Pype: I have added some lines about using AR to the LINKERS document of our wiki. Could you be so kind and proof-read it pls - or move it to whereever you reckon it's more appropriate?

Re:using GNU AR to create libraries *.a

Posted: Tue Apr 26, 2005 2:38 am
by Solar
Moved the stuff to LinkArchiver.

On second thought... does any of the other linkers (except GNU 'ld') work with .a archives?