using GNU AR to create libraries *.a

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
distantvoices
Member
Member
Posts: 1600
Joined: Wed Oct 18, 2006 11:59 am
Location: Vienna/Austria
Contact:

using GNU AR to create libraries *.a

Post 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!
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
User avatar
Candy
Member
Member
Posts: 3883
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:using GNU AR to create libraries *.a

Post 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
distantvoices
Member
Member
Posts: 1600
Joined: Wed Oct 18, 2006 11:59 am
Location: Vienna/Austria
Contact:

Re:using GNU AR to create libraries *.a

Post 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!
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
User avatar
Candy
Member
Member
Posts: 3883
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:using GNU AR to create libraries *.a

Post 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.
distantvoices
Member
Member
Posts: 1600
Joined: Wed Oct 18, 2006 11:59 am
Location: Vienna/Austria
Contact:

Re:using GNU AR to create libraries *.a

Post 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?
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
User avatar
Solar
Member
Member
Posts: 7635
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:using GNU AR to create libraries *.a

Post by Solar »

Moved the stuff to LinkArchiver.

On second thought... does any of the other linkers (except GNU 'ld') work with .a archives?
Every good solution is obvious once you've found it.
Post Reply