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.

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


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.