228Chapter7 • Miscellaneous Tools
command specific modifiers:
[a] - put file(s) after [member-name]
[b] - put file(s) before [member-name]
(same as [i])
[N] - use instance [count] of name
[f] - truncate inserted file names
[P] - use full path names when matching
[o] - preserve original dates
[u] - only replace files that are newer than
current archive contents
generic modifiers:
[c] - do not warn if the library had to be
created
[s] - create an archive index (cf. ranlib)
[S] - do not build a symbol table
[v] - be verbose
[V] - display the version number
[-X32_64] - (ignored)
ar: supported targets: elf32-i386 a.out-i386-linux efi-app-
ia32 elf32-little elf32-big srec symbolsrec tekhex binary ihex
trad-core
[root@boota /root]#
7.7.2Using the ranlib Utility
The
ranlib
command is used to create index entries inside an archive file. This can also
be done using –
s
command with the
ar
command while creating or updating an archive library
file. The following command creates index inside
libcommon.a
file. Note that these index
entries are stored inside the archive file and no other file is created.
ranlib libcommon.a
Most of the time you don’t need to run
ranlib
, as the latest version of the
ar
command
creates an index by itself. Index entries can be displayed using the
nm
command.
7.7.3Using the nm Utility
The
nm
utility is used to list symbols used in an object file. If no object file is provided on
the command line, the utility assumes the
a.out
file in the current directory as the default
object file and lists its symbols. A common use of the utility is listing functions defined in a
library. The following command displays object file names and functions defined in the library
file created with
ar
command in the previous section.
[root@boota]# nm -s libcommon.a
Archive index:
msg in common.o
main in ftp.o