Detailed explanation of AR commands in Linux

Source: Internet
Author: User
Tags posix

Function Description: create or modify a file to be kept, or extract files from the file to be kept.

Syntax: Ar [-dmpqrtx] [cfossuvv] [A <member files>] [B <member files>] [I <member files>] [keep files] [member files]

Note: Ar allows you to collect many files and make them a single file. All member files keep their original attributes and permissions.

Parameters:
Command Parameters
-D. Delete the member files in the keep file.
-M: change the order in which member files are stored.
-P: displays the content of the member file in the file.
-Q will append the user to the end of the file to be kept.
-R: insert the file into the storage file.
-T displays the files contained in the kept files.
-X saves the member files in your own files.
Option Parameter
A <member File> Insert the file into the specified member file in the keep file.
B <member File> before inserting a file into a specified member file in the kept file.
C. Create and keep documents.
F. To prevent too long file names from being compatible with Ar commands of other systems, you can use this parameter to cut down the names of long member files to be placed in the files.
I <member files> before you insert a specified member file in the kept file.
O preserve the date on which files are kept.
S if the file to be kept contains the object mode, you can use this parameter to create a symbol table for the file to be kept.
S does not generate a symbol table.
U only inserts new files with a specified date into the keep file.
Detailed information is displayed when the V program is executed.
V displays the version information.

 

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.oGenerate a library named test, which can be linked with-ltest. The library contains two modules: Hello. O and hello1.o. The option can contain '-' or none. 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.

2. Basic usage commands of Nm

Nm is used to list the symbols of the target file. The following is the format of the NM command:

NM [-A | -- debug-Syms] [-G | -- extern-only] [-B] [-c | -- demangle] [-d | -- Dynamic] [-S | -- print-armap] [-o | -- print-file-name] [-N | -- Numeric-Sort] [-p | -- no-Sort] [-r | -- reverse-Sort] [-- size-Sort] [-u | -- undefined-only] [-L | -- line-numbers] [-- help] [-- version] [-T Radix | -- Radix = Radix] [-p | -- portability] [-F format | -- format = format] [-- target = bfdname] [objfile...]

If the target file is not specified for the NM command, Nm assumes that the target file is a. Out. The following lists any options for this command. Most options include short formats starting with "-" And long formats starting.

  • -A,-o, or -- print-file-Name: add the file name before the names of the symbols found, instead of displaying the file name only once before all the symbols in the file.

    For example, the output of NM libtest. A is as follows:

    Cpthread. O:
    00000068 t Main _ 8 cpthreadpv
    00000038 t start _ 8 cpthread
    00000014 T _. _ 8 cpthread
    00000000 T _ 8 cpthread
    00000000? _ Frame_begin __
    .......................................

    The output of nm-A is as follows:

    Libtest. A: cpthread. O: 00000068 t Main _ 8 cpthreadpv
    Libtest. A: cpthread. O: 00000038 t start _ 8 cpthread
    Libtest. A: cpthread. O: 00000014 T _. _ 8 cpthread
    Libtest. A: cpthread. O: 00000000 T _ 8 cpthread
    Libtest. A: cpthread. O: 00000000? _ Frame_begin __
    ........................................ ..........................

  • -A or -- debug-Syms: displays debugging symbols.
  • -B: equivalent to -- format = BSD, used to be compatible with MIPS nm.
  • -C or -- demangle: decodes a low-level symbolic name (demangle) into a user-level name. This makes the C ++ function name readable.
  • -D or -- Dynamic: displays dynamic symbols. This option is only valid for dynamic targets (such as shared libraries of a specific type.
  • -F format: Output in format. Format can select BSD, sysv, or POSIX. This option is useful in GNU nm. The default value is BSD.
  • -G or -- extern-only: displays only external symbols.
  • -N,-V, or -- Numeric-sort: sort by the address corresponding to the symbol, rather than by the character order of the symbol name.
  • -P or -- no-sort: it is displayed in the order of symbols encountered in the target file, not sorted.
  • -P or -- Portability: Use the posix.2 standard output format instead of the default output format. It is equivalent to using any option-f posix.
  • -S or -- print-armap: contains the index when the symbol of the member in the column warehouse picking. The index content includes: Which modules contain the Mappings of names.
  • -R or -- reverse-sort: reverse the order (for example, ascending to descending ).
  • -- Size-sort: Sort symbols by size. The size is calculated based on the value of a symbol and the value of its next symbol.
  • -T Radix or -- Radix = Radix: Use the radix hexadecimal notation to display the symbolic value. Radix can only be "D" in decimal format, "O" in octal format, or "x" in hexadecimal format.
  • -- Target = bfdname: Specify the format of the target code, rather than the default format of the system.
  • -U or -- undefined-only: Only undefined symbols (those external symbols) are displayed ).
  • -L or -- line-numbers: Use debugging information for each symbol to find the file name and row number. For the defined symbols, find the line number of the symbol address. For undefined symbols, find the row number pointing to the symbol relocation entry. If you can find the row number information, it is displayed after the symbol information.
  • -V or -- version: displays the NM version number.
  • -- Help: displays any options of nm.

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.