Link Archiver: Difference between revisions

From OSDev.wiki
Jump to navigation Jump to search
[unchecked revision][unchecked revision]
Content added Content deleted
(Categorisation, Removed PFR)
(formatting changes)
Line 1: Line 1:
GNU '''ar''' is a utility that archives a series of files. 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.
==GNU ar==
GNU ar is a utility that archives a series of files. 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==
==Usage==
The tool itself is about as simple as its purpose. To archive a series of object files:
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
<pre>ar -rcs archive.a obj_fil1.o obj_fil2.o obj_fil3.o obj_fil4.o ... obj_filN.o</pre>


Then, to link against them:
Then, to link against them:
cc example.c archive.a -o example.bin
<pre>cc example.c archive.a -o example.bin</pre>


'''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.
'''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==
==See Also==
===External Links===
*[http://www.gnu.org/software/binutils/manual/html_chapter/binutils_1.html GNU 'ar' online manual].
*[http://www.gnu.org/software/binutils/manual/html_chapter/binutils_1.html GNU 'ar' online manual].



Revision as of 23:54, 4 April 2009

GNU ar is a utility that archives a series of files. 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

External Links