Ar (Unix)

Ar (Unix)

The archiver (also known simply as ar) is a Unix utility that maintains groups of files as a single archive file. Today, ar is generally used only to create and update static library files that the link editor or linker uses; it can be used to create archives for any purpose, but has been largely replaced by tar for purposes other than static libraries. ar is included as one of the GNU Binutils.

For example, to create an archive from files class1.o, class2.o, class3.o, the following command would be used: ar rcs libclass.a class1.o class2.o class3.oto compile a program that depends on class1.o, class2.o, and class3.o one could do: cc main.c libclass.ainstead of: cc main.c class1.o class2.o class3.o While it is technically possible to use the -L. switch and -lclass to achieve the same result in the linking phase, it is considered bad programming. As a rule of thumb, the -l should only be used for installed libraries.

File format details

The ar format has never been standardized; modern archives are based on a common format with two known variants, BSD and GNU.

Historically there have been other variants including AIX (small), AIX (big) and Coherent, which all vary significantly from the common format.

Debian ".deb" archives use the common format.

An ar file begins with a global header, followed by a header and data section for each file stored within the ar file.

The data section is 2 byte aligned. If it would end on an odd offset, a ' ' is used as filler.

Global header

The global header is a single field containing the magic ASCII string "!" followed by a single LF control character

File header

The common format is as follows.

Due to the limitations of file name length and format, both the GNU and BSD variants devised different methods of achieving extended filenames.

BSD variant

BSD ar store extended filenames by placing the string "#1/" followed by the file name length in the file name field, and appending the real filename to the file header.

GNU variant

GNU ar stores multiple extended filenames in the data section of a file with the name "//", this record is referred to by future headers. A header references an extended filename by storing a "/" followed by a decimal offset to the start of the filename in the extended filename data section. The format of this "//" file itself is simply a list of the long filenames, each separated by one or more LF characters. Note that the decimal offsets are number of characters, not line or string number within the "//" file.

GNU ar uses a '/' to mark the end of the filename, this allows for the use of spaces without the use of an extended filename.

GNU ar uses the special filename "/" to denote that the following data entry contains a symbol lookup table, which is used in ar libraries to speed up access. This symbol table is built in three parts which are recorded together as contiguous data.

# A 32-bit big endian integer, giving the number of entries in the table.
# A set of 32-bit big endian integers. One for each symbol, recording the position within the archive of the header for the file containing this symbol.
# A set of Zero-terminated strings. Each is a symbol name, and occurs in the same order as the list of positions in part 2.

The special file "/" is not terminated with a specific sequence, the end is assumed once the last symbol name has been read.

ee also

*.deb
*archive formats
*List of Unix programs

External links

*
*
* [http://www.freebsd.org/cgi/man.cgi?query=ar&apropos=0&sektion=0&manpath=Unix+Seventh+Edition&format=html Manual page for Unix Seventh Edition's ar]
* [http://manpagehelp.net/manpage/freebsd/man1/ar.html Man Page FreeBSD] with comments
* "The 32-bit PA-RISC Run-time Architecture Document, HP-UX 11.0 Version 1.0," Hewlett-Packard, 1997.
See "Chapter 4: Relocatable Libraries". Available at [http://devresource.hp.com/drc/STK/docs/archive/rad_11_0_32.pdf] (devresource.hp.com)


Wikimedia Foundation. 2010.

Игры ⚽ Поможем написать курсовую

Look at other dictionaries:

  • Unix — (officially trademarked as UNIX, sometimes also written as Unix with small caps) is a computer operating system originally developed in 1969 by a group of AT T employees at Bell Labs, including Ken Thompson, Dennis Ritchie, Douglas McIlroy, and… …   Wikipedia

  • UNIX — Ken Thompson und Dennis Ritchie Basisdaten Entwickler …   Deutsch Wikipedia

  • Unix — Kommandozeile (Unix Prompt) Basisdaten Entwickler Ken Thompso …   Deutsch Wikipedia

  • Unix — (registrado oficialmente como UNIX®) es un sistema operativo portable, multitarea y multiusuario; desarrollado, en principio, en 1969 por un grupo de empleados de los laboratorios Bell de AT T, entre los que figuran Ken Thompson, Dennis Ritchie y …   Wikipedia Español

  • UNIX — UNIX, parfois écrit « Unix », avec des petites capitales, est un système d exploitation multitâche et multi utilisateur créé en 1969, conceptuellement ouvert et fondé sur une approche par laquelle il offre de nombreux petits outils… …   Wikipédia en Français

  • Unix — (marque déposée officiellement comme UNIX, parfois aussi écrit comme Unix avec les petites capitalisations) est le nom d un système d exploitation multitâche et multi utilisateur créé en 1969, conceptuellement ouvert et fondé sur une approche par …   Wikipédia en Français

  • Unix time — Unix time, or POSIX time, is a system for describing points in time, defined as the number of seconds elapsed since midnight Coordinated Universal Time (UTC) of January 1 1970, not counting leap seconds. It is widely used not only on Unix like… …   Wikipedia

  • Unix-подобная операционная система — Генеалогическое дерево UNIX подобных ОС UNIX подобная операционная система (иногда сокр. *nix)  система, которая образовалась под влиянием UNIX. Термин включает свободные/открытые операционные системы, образованные от UNIX компании …   Википедия

  • UNIX — 〈[ju:nıx] EDV〉 Betriebssystem für Computer, das zum großen Teil in der Programmiersprache C geschrieben ist [engl.] * * * UNIX   [ursprünglich UNICS, Abk. für Uniplexed Information and Computing System, dt. »nicht multiplextes (vielseitiges)… …   Universal-Lexikon

  • UNIX-Kommandos — Unix Systeme zeichnen sich durch eine Vielzahl von Kommandos aus, mit denen sich über eine Shell das Betriebssystem bedienen lässt. Die Syntax dieser Kommandos weicht unter den verschiedenen Systemen voneinander ab. Es existieren die beiden… …   Deutsch Wikipedia

  • Unix-Befehle — Unix Systeme zeichnen sich durch eine Vielzahl von Kommandos aus, mit denen sich über eine Shell das Betriebssystem bedienen lässt. Die Syntax dieser Kommandos weicht unter den verschiedenen Systemen voneinander ab. Es existieren die beiden… …   Deutsch Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”