226Chapter7 • Miscellaneous Tools
7.7Using GNU Binary Utilities
GNU binutils is a package of many utilities that are related to manipulating library files or get-
ting information about different types of binary files. These utilities range from finding strings in
a binary file, creating library files, displaying information about binary files, assembling and dis-
assembling files, and so on. This section contains an introduction to most commonly used binary
utilities.
7.7.1Using the ar Utility
Files can be stored into a single file using the
ar
utility. The file into which multiple files
are stored is called an
archive
. The
ar
program retains file permissions, ownerships and other
properties of the original files. These files can be extracted from the archive later on, if required.
The program also creates an index within the archive file that is used to speed up locating a com-
ponent (or
members
) of the archive.
From the development point of view, the
ar
program is used to create libraries of func-
tions. These libraries are then used with other object files to link an executable file. The conven-
tional name of these library files is
lib{name}.a
where
name
is any string used as a library
name. For example, a library named
common
will be stored in a file called
libcommon.a
.
The
ar
program performs one of the following tasks depending upon options used on the
command line.
•Delete a file from the archive (option
d
)
•Move files in the archive (option
m
)
•Print a list of files in the archive (option
p
)
•Append files to the archive (option
q
)
•Insert new files in the archive by replacing if a file already exists in the archive (option
r
)
•Displaying contents of an archive (option
t
)
•Extracting files from an archive (option
x
)
More options can be used in combination with these options to perform additional tasks.
In this section we shall use some very common options to show you how the
ar
program is used
in a software development environment.
We have used
ar
version 2.10.91 in this book. You can display a current version of the
program on your system using –
V
option as shown below. The
ar
utility is usually used because
of its compatibility with
ld
, the dynamic loader.
[root@boota ar]# ar -V
GNU ar 2.10.91
Copyright 1997, 98, 99, 2000, 2001 Free Software Foundation,
Inc.
This program is free software; you may redistribute it under
the terms of the GNU General Public License. This program has
absolutely no warranty.
[root@boota ar]#