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!
using GNU AR to create libraries *.a
-
distantvoices
- Member

- Posts: 1600
- Joined: Wed Oct 18, 2006 11:59 am
- Location: Vienna/Austria
- Contact:
using GNU AR to create libraries *.a
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
BlueillusionOS iso image
Re:using GNU AR to create libraries *.a
both: almost
all iirc, ar command was checked with manpage
Code: Select all
ar -rcs bla.a *.o
ld -o totalfile.elf *.o bla.a
-
distantvoices
- Member

- Posts: 1600
- Joined: Wed Oct 18, 2006 11:59 am
- Location: Vienna/Austria
- Contact:
Re:using GNU AR to create libraries *.a
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!
Thanks for reply!
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
BlueillusionOS iso image
Re:using GNU AR to create libraries *.a
Well, no... not entirelybeyond 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!
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

- Posts: 1600
- Joined: Wed Oct 18, 2006 11:59 am
- Location: Vienna/Austria
- Contact:
Re:using GNU AR to create libraries *.a
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?
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
BlueillusionOS iso image
Re:using GNU AR to create libraries *.a
Moved the stuff to LinkArchiver.
On second thought... does any of the other linkers (except GNU 'ld') work with .a archives?
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.