Use of Ar and NM commands

xiaoxiao2021-03-06  80

Use of Ar and NM commands

Summary

When our program is often used, and this module is also used in other programs. At this time, according to software reuse, we should generate them to create a library, making it later to reduce development code. Here is two commands ar and nm to operate in the library. (2002-07-09 13:06:05)

BY scholar

When our program is often used, and this module is also used in other programs. At this time, according to software reuse, we should generate them to create a library, making it later to reduce development code. Here is two commands ar and nm to operate in the library. 1.ar Basic Usage AR Commands can be used to create, modify the library, or you can propose a single module from the library. The library is a single file that contains some of the other files organized according to a specific structure (called MEMBER for this library file). The content, mode, timestamp, the owner, and groups of the original file are reserved in the library file. Below is the format of the ar command:           {dmpqrtx} [abcfilnopssuvv] [MEMBERNAME] [count] Archive Files ... For example we can generate a library with ar rv libtest.a hello.o hello1.o, The library name is TEST, which can be linked with the -ltest when link. Two modules Hello.o and Hello1.o are stored in this library. You can have '-' characters before the option or no. Let's take a look at the operational options and options for the command. Now we call the {DMPQRTX} section as an operational option, and the [Abcfilnopssuvv] section is called an option. The operation options in {dmpqrtx} can only use one in the command, and their meaning is as follows:

d: Delete the module from the library. Specify the module to be deleted by the original file name. If you use any option v, list each module deleted. m: This operation is a member in a library. If there are several modules in the library have the same symbol definition (such as function definition), the position of the member is important. If you do not specify an option, any specified member will move to the finals of the library. You can also move to the specified location using 'A', 'B', or 'I' option. P: The member specified in the library is displayed to the standard output. If you specify an option V, the member's name will be displayed before the content of the output member. If there is no name of the member, the files in all libraries will be displayed. Q: Quick addition. Add new modules to the end of the library. Do not check if it needs to be replaced. 'A', 'b', or 'i' option has no effect on this operation, the module always has the end of the subsequent library. If you use any option v, each module is listed. At this time, the library's symbol table is not updated, and the symbol table index of the library can be updated with 'Ar S' or RANLIB. R: Insert the module (replace) in the library. When the inserted module name has existed in the library, the same name is replaced. If a module in several modules does not exist in the library, AR displays an error message and does not replace other symbol modules. By default, new members increase the end of the library, and other options can be used to change the increased position. T: The module table list of the library is displayed. The module name is generally displayed. x: Extract a member from the library. If you do not specify the module to be extracted, all modules in the library are extracted. Here are options that can be used in conjunction with the operational options:

A: Add a new file after an existing member of the library. If you use any option a, you should specify a member name that already exists in the command line Membername parameter. B: Add a new file in front of an existing member of the library. If you use any option B, you should specify a member name that already exists in the command line of the MEMBERNAME parameter. C: Create a library. Will be created regardless of whether the library is present. f: Truncate the designated name in the library. By default, the length of the file name is unrestricted, and this parameter can be used to ensure the name of the file to ensure compatibility with other systems. I: Add a new file in front of a presented member of the library. If you use any option I, you should specify a member name already existing in the command line (similar option B) for the MEMBERNAME parameter. l: No N: Use the count parameter to specify the number of extracted or output when there are multiple identical file names in the library. o: When the member is extracted, the original data of the member is retained. If this option is not specified, the time extracted module will be marked as the time extracted. P: Use full path name when performing file name matches. Ar Can't use a full path name when creating a library (such library files do not conform to the POSIX standard), but some tools can. S: Write a target file index to the library, or update an existing target file index. Even libraries without any changes are also doing this action. Making Ar s for a library is equivalent to do RANLIB for the library. S: Do not create a target file index, which speeds up when creating a larger library. u: Generally, command ar r ... Insert all listed files to the library, if you only want to insert a new file in the list of files in the file, you can use this option. This option is only used for R operation options. V: This option uses to display additional information for performing an action option. V: Display the version of Ar. 2. nm Basic Usage Command NM is used to list the symbol list 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-number] [--help] [- version] [-t radix | --radix = radix] [-P | --portability] [-f format | --format = format] [- target = bfDName] [objfile ...] If the target file is not indicated for the nm command, the NM assumes that the target file is a.out . The options for this command are listed below, and most of the short formats that support the "-" start-ups and "-" begin.

转载请注明原文地址:https://www.9cbs.com/read-121503.html

New Post(0)