Next: ,Up: ar



1.1 Controlling ar on the Command Line

ar [-X32_64] [-]p[mod [relpos] [count]] archive [member...]

When you use ar in the Unix style, ar insists on at least twoarguments to execute: one keyletter specifying the operation(optionally accompanied by other keyletters specifyingmodifiers), and the archive name to act on.

Most operations can also accept further member arguments,specifying particular files to operate on.

gnu ar allows you to mix the operation code p and modifierflags mod in any order, within the first command-line argument.

If you wish, you may begin the first command-line argument with adash.

The p keyletter specifies what operation to execute; it may beany of the following, but you must specify only one of them:

d

Delete modules from the archive. Specify the names of modules tobe deleted as member ...; the archive is untouched if youspecify no files to delete.

If you specify the v modifier, ar lists each moduleas it is deleted.

m

Use this operation to move members in an archive.

The ordering of members in an archive can make a difference in howprograms are linked using the library, if a symbol is defined in morethan one member.

If no modifiers are used with m, any members you name in themember arguments are moved to the end of the archive;you can use the a, b, or i modifiers to move them to aspecified place instead.

p

Print the specified members of the archive, to the standardoutput file. If the v modifier is specified, show the membername before copying its contents to standard output.

If you specify no member arguments, all the files in the archive areprinted.

q

Quick append; Historically, add the files member ... to the end ofarchive, without checking for replacement.

The modifiers a, b, and i do not affect thisoperation; new members are always placed at the end of the archive.

The modifier v makes ar list each file as it is appended.

Since the point of this operation is speed, the archive's symbol tableindex is not updated, even if it already existed; you can use ar s orranlib explicitly to update the symbol table index.

However, too many different systems assume quick append rebuilds theindex, so gnu ar implements q as a synonym for r.

r

Insert the files member ... into archive (withreplacement). This operation differs from q in that anypreviously existing members are deleted if their names match those beingadded.

If one of the files named in member ... does not exist, ardisplays an error message, and leaves undisturbed any existing membersof the archive matching that name.

By default, new members are added at the end of the file; but you mayuse one of the modifiers a, b, or i to requestplacement relative to some existing member.

The modifier v used with this operation elicits a line ofoutput for each file inserted, along with one of the letters a orr to indicate whether the file was appended (no old memberdeleted) or replaced.

t

Display a table listing the contents of archive, or thoseof the files listed in member ... that are present in thearchive. Normally only the member name is shown; if you also want tosee the modes (permissions), timestamp, owner, group, and size, you canrequest that by also specifying the v modifier.

If you do not specify a member, all files in the archiveare listed.

If there is more than one file with the same name (say, fie) inan archive (say b.a), ar t b.a fie lists only thefirst instance; to see them all, you must ask for a completelisting—in our example, ar t b.a.

x

Extract members (named member) from the archive. You canuse the v modifier with this operation, to request thatar list each name as it extracts it.

If you do not specify a member, all files in the archiveare extracted.

Files cannot be extracted from a thin archive.

A number of modifiers (mod) may immediately follow the pkeyletter, to specify variations on an operation's behavior:

a

Add new files after an existing member of thearchive. If you use the modifier a, the name of an existing archivemember must be present as the relpos argument, before thearchive specification.

b
Add new files before an existing member of thearchive. If you use the modifier b, the name of an existing archivemember must be present as the relpos argument, before thearchive specification. (same as i).
c

Create the archive. The specified archive is alwayscreated if it did not exist, when you request an update. But a warning isissued unless you specify in advance that you expect to create it, byusing this modifier.

f
Truncate names in the archive. gnu ar will normally permit filenames of any length. This will cause it to create archives which arenot compatible with the native ar program on some systems. Ifthis is a concern, the f modifier may be used to truncate filenames when putting them in the archive.
i
Insert new files before an existing member of thearchive. If you use the modifier i, the name of an existing archivemember must be present as the relpos argument, before thearchive specification. (same as b).
l
This modifier is accepted but not used.
N
Uses the count parameter. This is used if there are multipleentries in the archive with the same name. Extract or delete instancecount of the given name from the archive.
o

Preserve the original dates of members when extracting them. Ifyou do not specify this modifier, files extracted from the archiveare stamped with the time of extraction.

P
Use the full path name when matching names in the archive. gnu ar can not create an archive with a full path name (such archivesare not POSIX complaint), but other archive creators can. This optionwill cause gnu ar to match file names using a complete pathname, which can be convenient when extracting a single file from anarchive created by another tool.
s

Write an object-file index into the archive, or update an existing one,even if no other change is made to the archive. You may use this modifierflag either with any operation, or alone. Running ar s on anarchive is equivalent to running ranlib on it.

S

Do not generate an archive symbol table. This can speed up building alarge library in several steps. The resulting archive can not be usedwith the linker. In order to build a symbol table, you must omit theS modifier on the last execution of ar, or you must runranlib on the archive.

T

Make the specified archive a thin archive. If it alreadyexists and is a regular archive, the existing members must be presentin the same directory as archive.

u

Normally, ar r ... inserts all fileslisted into the archive. If you would like to insert only thoseof the files you list that are newer than existing members of the samenames, use this modifier. The u modifier is allowed only for theoperation r (replace). In particular, the combination qu isnot allowed, since checking the timestamps would lose any speedadvantage from the operation q.

v
This modifier requests the verbose version of an operation. Manyoperations display additional information, such as filenames processed,when the modifier v is appended.
V
This modifier shows the version number of ar.

ar ignores an initial option spelt -X32_64, forcompatibility with AIX. The behaviour produced by this option is thedefault for gnu ar. ar does not support any of the other-X options; in particular, it does not support -X32which is the default for AIX ar.

Reference Home

Corrections, suggestions, and new documentation should be posted to the Forum.

The text of the Arduino reference is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.