Link Archiver: Difference between revisions

From OSDev.wiki
Jump to navigation Jump to search
[unchecked revision][unchecked revision]
Content added Content deleted
No edit summary
 
m (Bot: Replace deprecated source tag with syntaxhighlight)
 
(7 intermediate revisions by 6 users not shown)
Line 1: Line 1:
{{Convert}}
{{Stub}}
{{Infobox_Tool
|name=GNU Archiver
|website=http://www.gnu.org/software/binutils/
}}


GNU '''ar''' is a utility that archives a series of files and is part of the [[binutils]] package. It is used to take a group of files, and combine them all into one. This allows one to then compress, send, or most importantly and commonly, link the files into a program.
You have many object files and your linking line for a program in your OS grows longer and longer? GNU AR helps.


== Usage ==
It creates archives of object files alongside with a table of the symbols, which each object file (==member) sports.
The tool itself is about as simple as its purpose. To archive a series of object files:
<syntaxhighlight lang="bash">ar -rcs archive.a obj_fil1.o obj_fil2.o obj_fil3.o obj_fil4.o ... obj_filN.o</syntaxhighlight>


Then, to link against them:
USAGE: =ar -rcs archive.a obj_fil1.o obj_fil2.o obj_fil3.o obj_fil4.o ... obj_filN.o=
<syntaxhighlight lang="bash">cc example.c archive.a -o example.bin</syntaxhighlight>


'''Important''': If you link other object files besides the library ''archive.a'', take care that the ''archive.a'' is right behind these object files (or have it be the very last file in the list of files to link) - so the linker can resolve the one or other occurrence of a symbol which is covered by some member of the ''archive.a'' library.
You link your program's object file against =crt0.o= and the =archive.a= file.


== See Also ==
Important: If you link other object files besides the library =archive.a=, take care that the =archive.a= is right behind these object files (or have it be the very last file in the list of files to link) - so the linker can resolve the one or other occurrence of a symbol which is covered by some member of the =archive.a= library.


=== Articles ===
See also the [GNU 'ar' online manual | http://www.gnu.org/software/binutils/manual/html_chapter/binutils_1.html].
* [[binutils]]
* [[LD|ld]]

=== External Links ===
* [https://sourceware.org/binutils/docs/binutils/ar.html#ar GNU 'ar' online manual].

[[Category:Binutils]]

Latest revision as of 04:34, 9 June 2024

This page is a stub.
You can help the wiki by accurately adding more contents to it.

GNU Archiver

[[Image:{{{image}}}|300px|]]
Website:http://www.gnu.org/software/binutils/

GNU ar is a utility that archives a series of files and is part of the binutils package. It is used to take a group of files, and combine them all into one. This allows one to then compress, send, or most importantly and commonly, link the files into a program.

Usage

The tool itself is about as simple as its purpose. To archive a series of object files:

ar -rcs archive.a obj_fil1.o obj_fil2.o obj_fil3.o obj_fil4.o ... obj_filN.o

Then, to link against them:

cc example.c archive.a -o example.bin

Important: If you link other object files besides the library archive.a, take care that the archive.a is right behind these object files (or have it be the very last file in the list of files to link) - so the linker can resolve the one or other occurrence of a symbol which is covered by some member of the archive.a library.

See Also

Articles

External Links