Open In App

ranlib command in Linux with Examples

Last Updated : 17 Apr, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

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.

Syntax:

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.

Options:

  • –help: This option will show usage information for ranlib.
    ranlib --help

  • –version: This option will show the version number of ranlib.
    ranlib --version

  • -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.

    Example:

    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.

    Example :

    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.

    Example:

    ranlib -U fruits.a

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads