ranlib command in Linux with Examples
Last Updated :
08 Oct, 2024
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 a 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
Basic Example
It will generate an 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.
Common Options Used with the ranlib command
Here are the key options you can use with ranlib:
1. --help:
This option displays usage information for the ranlib command, making it useful for users who need a quick reference on how to use the tool.
Example:
ranlib --help

2. --version:
This option shows the version of the ranlib command installed on your system.
Example:
ranlib --version

3. -D (Deterministic Mode):
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.
4. -t (Timestamp Update):
This option updates the timestamp of the symbol map within the archive. It is often used when updating existing archives to ensure the symbol map remains current.
Example :
ranlib -t fruits.a
5. -U (Non-Deterministic Mode):
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
Conclusion
The ranlib command plays a vital role in the management of static libraries in Linux, particularly for C and C++ developers. By generating an index for an archive, ranlib enhances the efficiency of the linking process, enabling faster access to symbols and ensuring routines within the library can interact effectively. With options for deterministic and non-deterministic modes, ranlib also helps developers maintain reproducible builds, which is crucial in modern software development.
Similar Reads
od command in Linux with example The od (octal dump) command in Linux is a versatile tool used to display file contents in various formats, with the default being octal. This command is particularly useful for debugging scripts, examining binary files, or visualizing non-human-readable data like executable code. It allows users to
6 min read
How to Change User Password in Linux | passwd Command Securing user accounts is a fundamental aspect of maintaining a robust and secure Linux system. One essential task is changing user passwords regularly to prevent unauthorized access. The passwdpasswd command in Linux provides a straightforward and effective way to modify user passwords. This articl
8 min read
Paste command in Linux with examples Paste command is one of the useful commands in Unix or Linux operating system. It is used to join files horizontally (parallel merging) by outputting lines consisting of lines from each file specified, separated by tab as delimiter, to the standard output. When no file is specified, or put dash ("-"
6 min read
pidof Command in Linux with Examples pidof command is used to find out the process IDs of a specific running program. It is basically an identification number that is automatically assigned to each process when it is created. Syntax: pidof [options] program1 program2 ... programNWorking with Pidof Command 1. To find pid of any process
2 min read
How to Check Network Connectivity in Linux | ping Command Ensuring a stable and reliable internet connection is crucial for seamless navigation and efficient communication in the world of Linux. The "ping" command is a powerful tool that allows users to check the status of their internet connection and diagnose network-related issues. In this article, we w
7 min read
Pinky command in Linux with Examples Pinky command is a user information lookup command which gives details of all the users logged in. This tool is generally used by system administrators. It is similar to the finger tool but in many Linux, Systems pinky comes pre-installed while finger doesn't, so this command is useful in case you d
2 min read
pmap command in Linux with Examples The pmap command in Linux is a powerful utility used to display the memory map of a process. A memory map provides insight into how memory is allocated and distributed within a running process. This can be incredibly useful for developers and system administrators when debugging memory issues, optim
3 min read
halt, poweroff and reboot Commands in Linux In Linux systems, the halt, poweroff, and reboot commands are essential tools for controlling the system's hardware by stopping the CPU, shutting down the system, or restarting it. These commands are typically restricted to superusers, as they involve critical actions that impact the system hardware
4 min read
printf command in Linux with Examples The 'printf' command in Linux is a versatile tool used to display formatted text, numbers, or other data types directly in the terminal. Like the 'printf' function in programming languages like C, the Linux printf command allows users to format output with great precision, making it ideal for script
4 min read
How to List Running Processes in Linux | ps Command As we all know Linux is a multitasking and multi-user system. So, it allows multiple processes to operate simultaneously without interfering with each other. Process is one of the important fundamental concepts of the Linux OS. A process is an executing instance of a program that carries out differe
10 min read