- NAME
- ar - create, modify, and extract from archives
d Delete modules from the archive. Specify the names of modules to be deleted as member...; the
archive is untouched if you specify no files to delete.
p Print the specified members of the archive, to the standard output file.
r Insert the files member... into archive (with replacement).
t Display a table listing the contents of archive, or those of the files listed in member... that
are present in the archive.
s Write an object-file index into the archive, or update an existing one, even if no other change
is made to the archive.
v This modifier requests the verbose version of an operation.
- void
-
print1(void)
-
{
-
printf("First print\n");
- }
print2.c
- void
-
print2(void)
-
{
-
printf("Second print\n");
- }
create static lib file: lib[name].a
- gcc -c print1.c print2.c
- ar -rsv libprint.a print1.o print2.o
test.c
- #include <stdio.h>
-
-
int
-
main(void)
-
{
-
print1();
-
print2();
-
-
return 0;
- }
use:
- gcc -o test test.c -L./ -lprint
- -llibrary
-
- Search the library named library when linking.
-
- The linker searches a standard list of directories for the library, which is actually a file
named liblibrary.a. The linker then uses this file as if it had been specified precisely by
name.
The directories searched include several standard system directories plus any that you specify
with -L