Instructions and examples to explain the command linux ar

About Command

  • ar command can be used to create, modify library, you can also put forward a single module from the library. Library is a separate file, which contains a number of other documents organized according to a particular structure (referred to as library member in this document). The contents of the original file, mode, timestamp, owner, group, and other properties are preserved in the library file.
  • ar be a collection of files, kept as a single file. In the documents kept in the file are all members of the original property and ownership rights.

Instructions for use

  • Create a static library .a file (such as libcalc.a). In C / C ++ is often used when developing programs, generally written in the makefile, sometimes used in shell scripts.

Common parameters

  • Format: ar rcs libxxx.a xx1.o xx2.o

Parameter r: Insert (replacement) in the library. When inserting the module name already exists in the library, the replacement modules with the same name. If there are several modules in a module is not present in the library, ar displays an error message, is not replaced by another module of the same name. By default, new members increase at the end of the library, you can use any of the other options to change the location of the increase. 
Parameters c: create a library. Regardless of whether the library exists, it will be created. 
Parameters s: create the target file index, which can speed up the time to create a larger library. (NOTE: If you do not need to create an index, the S-parameters can be changed to upper case; if .a index file is missing, can be added using ranlib command)

  • Format: ar t libxxx.a

Display libraries in which the target file, only the display name.

  • Format: ar tv libxxx.a

Display libraries in which the target file, details file name, time, size, etc. is displayed.

  • Format: nm -s libxxx.a

Display library file index table.

  • Format: ranlib libxxx.a

Create an index table for the library file.

Published 21 original articles · won praise 5 · views 10000 +

Guess you like

Origin blog.csdn.net/icodestechnology/article/details/90544799