ranlib command in Linux with Examples
ranlib command in Linux is used to generate index to archive. ranlib generates an index to the contents of an archive and it will be stored in the archive. The index lists each symbol defined by a member of an archive which is simply relocatable object file. You may use nm -s or nm –print-armap to list all of this index. An archive with such an index speeds up the linking to the library and allows routines in the library to call each other without regard to their placement in the archive. The GNU ranlib program is another form of GNU ar; running ranlib is completely equivalent to running ar -s.
ranlib [--plugin name] [-DhHvVt] archive
Example: It will generate index to archive as shown in the below example.
Explanation: As you can see in above example we are archiving three files named main.o, point.o and rectangle.o to fruits.a and then using ranlib command generating an index to the contents of an archive and it will be stored in the archive.
- –help: This option will show usage information for ranlib.
- –version: This option will show the version number of ranlib.
- -D : This option will operate in deterministic mode. The symbol map archive of member’s header will show zero for the UID, GID, and timestamp. When this option is being used, multiple runs will produce identical output files.
ranlib -D fruits.a
Explanation: As you can see in above example we are archiving three files named main.o, point.o and rectangle.o to fruits.a and then using ranlib command with the option -D we are changing the mode of operation to deterministic and generating an index to the contents of an archive and it will stores it in the archive.
- -t : This option will update the timestamp of the symbol map of an archive.
ranlib -t fruits.a
- -U: This option do not operate in deterministic mode. This is exactly the inverse of the -D option. The archive index will get actual UID, GID, timestamp, and file mode values. If binutils was configured without using –enable-deterministic-archives, then this mode is set by default.
ranlib -U fruits.a