Some examples are:
- To create a library, enter:
ar -v -q lib.a strlen.o strcpy.o
If the lib.a library does not exist, this command creates it and enters into it copies of the files strlen.o and strcpy.o. If the lib.a library does exist, then this command adds the new members to the end without checking for duplicate members. The v flag sets verbose mode, in which the ar command displays progress reports as it proceeds.
- To list the table of contents of a library, enter:
ar -v -t lib.a
This command lists the table of contents of the lib.a library, displaying a long listing similar to the output of the ls -l command. To list only the member file names, omit the -v flag.
- To replace or add new members to a library, enter:
ar -v -r lib.a strlen.o strcat.o
This command replaces the members strlen.o and strcat.o. If lib.a was created as shown in example 1, then the strlen.o member is replaced. A member named strcat.o does not already exist, so it is added to the end of the library.
- To specify where to insert a new member, enter:
ar -v -r -b strlen.o lib.a strcmp.o
This command adds the strcmp.o file, placing the new member before the strlen.o member.
- To update a member if it has been changed, enter:
ar -v -r -u lib.a strcpy.o
This command replaces the existing strcpy.o member, but only if the file strcpy.o has been modified since it was last added to the library.
- To change the order of the library members, enter:
ar -v -m -a strcmp.o lib.a strcat.o strcpy.o
This command moves the members strcat.o and strcpy.o to positions immediately after the strcmp.o member. The relative order of the strcat.o and strcpy.o members is preserved. In other words, if the strcpy.o member preceded the strcat.o member before the move, it still does.
- To extract library members, enter:
ar -v -x lib.a strcat.o strcpy.o
This command copies the members strcat.o and strcpy.o into individual files named strcat.o and strcpy.o, respectively.
- To extract and rename a member, enter:
ar -p lib.a strcpy.o >stringcopy.o
This command copies the member strcpy.o to a file named stringcopy.o.
- To delete a member, enter:
ar -v -d lib.a strlen.o
This command deletes the member strlen.o from the lib.a library.
- To create an archive library from multiple shared modules created with the ld command, enter:
ar -r -v libshr.a shrsub.o shrsub2.o shrsub3.o ...
This command creates an archive library named libshr.a from the shared modules named shrsub.o, shrsub2.o, shrsub3.o, and so on. To compile and link the main program using the libshr.a archive library, use the following command:
cc -o main main.c -L/u/sharedlib -lshr
The main program is now executable. Any symbols referenced by the main program that are contained by the libshr.a archive library have been marked for deferred resolution. The -l flag specifies that the libshr.a library be searched for the symbols.
- To list the contents of lib.a, ignoring any 32-bit object file, enter:
ar -X64 -t -v lib.a
- To extract all 32-bit object files from lib.a, enter:
ar -X32 -x lib.a
- To list all files in lib.a, whether 32-bit, 64-bit, or non-objects, enter:
ar -X32_64 -t -v lib.a
No comments:
Post a Comment