Linux ar command

Source: Internet
Author: User

When there are frequently used modules in our program and such modules are also used in other programs, we should generate libraries based on the idea of software reuse, so that later programming can reduce the amount of development code. Here we will introduce the AR command for database operations.
1. Basic ar usage
The ar command can be used to create and modify a database, or to propose a single module from the database. The library is a separate file that contains other files organized according to a specific structure (called the member of the library file ). Attributes of the original file, such as content, mode, timestamp, owner, and group, are kept in the library file.
The format of the Ar command is as follows:
Ar [-] {dmpqrtx} [abcfilnopssuvv] [membername] [count] archive files...
For example, we can useAr RV libtest. A hello. O hello1.oCome
Generate a library named test, which can be linked with-ltest. The library contains two modules: Hello. O and hello1.o. The option can contain the '-' character or
No. Next let's take a look at the operation options and any options of the command. Now we call the {dmpqrtx} part as an operation option, and the [abcfilnopssuvv] Part as any option.
The operation options in {dmpqrtx} can only be used in the command and must use one of them. Their meanings are as follows:

  • D: delete a module from the database. Specify the module to be deleted based on the original file name of the module. If any option V is used, each deleted module is listed.
  • M: This operation is a member moving in a library. If several modules in the library have the same symbolic definition (such as function definition), the order of member positions is very important. If no option is specified, any specified member will be moved to the end of the database. You can also use the 'A', 'B', or 'I' option to move to the specified position.
  • P: displays the specified members in the database to the standard output. If any option V is specified, the member name is displayed before the content of the output member. If no member name is specified, all files in the database are displayed.
  • Q: Fast append. Add a new module to the end of the database. Do not check whether replacement is required. The 'A', 'B', or 'I' option does not affect this operation. The module always appends the end of the library. If any option V is used, each module is listed. The symbol table of the library is not updated. You can use 'ar s' or ranlib to update the index of the symbol table of the library.
  • R: Insert a module (replace) into the database ). If the inserted Module name already exists in the Database, replace the module with the same name. If one of the modules does not exist in the library, ar displays an error message and does not replace other modules with the same name. By default, new members are added at the end of the database. You can use other options to change the position of the added member.
  • T: displays the list of modules in the database. Generally, only the module name is displayed.
  • X: extract a member from the database. If the module to be extracted is not specified, all modules in the library are extracted.

The following describes any options that can be used with operation options:

  • A: Add a new file to an existing member of the database. If you use any option A, you should specify an existing member name for the membername parameter in the command line.
  • B: Add a new file before an existing member of the database. If option B is used, an existing member name should be specified for the membername parameter in the command line.
  • C: Create a database. Whether or not the database exists will be created.
  • F: truncates the specified name in the database. By default, the file name length is unrestricted. You can use this parameter to shorten the file name to ensure compatibility with other systems.
  • I: Add a new file before an existing member of the database. If any option I is used, you should specify an existing member name (similar to any option B) for the membername parameter in the command line ).
  • L: Not used yet
  • N: used with the Count parameter to specify the number of extracted or output files when multiple identical file names exist in the database.
  • O: when a Member is extracted, the original data of the member is retained. If this option is not specified, the extracted module time is marked as the extracted time.
  • P: use the full path name for file name matching. Ar cannot use full path names when creating a library (such library files do not comply with POSIX standards), but some tools are acceptable.
  • S: Write a target file index to the database, or update an existing target file index. This action is even performed for libraries that have not changed. Doing ar s for a library is equivalent to doing ranlib for the library.
  • S: do not create the target file index, which can speed up the time when creating a large database.
  • U: Generally, the command ar r... insert all listed files to the database. If you only want to insert files in the list file that are new to files with the same name as the files in the database, you can use this option. This option is only used for r operation.
  • V: This option is used to display additional information about the operation options.
  • V: displays the AR version.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.