ar

 ar用途: 维护链接编辑器使用的索引库。

ar命令可以用来创建、修改库,也可以从库中提出单个模块。库是一单独的文件,里面包含了 按照特定的结构组织起来的其它的一些文件(称做此库文件的member)。原始文件的内容、模式、时间戳、属主、组等属性都保留在库文件中。

mutian@mutian:~/share/test/test$ ar --help
Usage: ar [emulation options] [-]{dmpqrstx}[abcDfilMNoPsSTuvV] [--plugin <name>] [member-name] [count] archive-file file...
       ar -M [<mri-script]
 commands:
  d            - delete file(s) from the archive
  m[ab]        - move file(s) in the archive
  p            - print file(s) found in the archive
  q[f]         - quick append file(s) to the archive
  r[ab][f][u]  - replace existing or insert new file(s) into the archive
  s            - act as ranlib
  t            - display contents of archive
  x[o]         - extract file(s) from the archive
   [v]          - be verbose

 

mutian@mutian:~/share/test/test$ ar -r libtest.a a.o b.o
ar: creating libtest.a
mutian@mutian:~/share/test/test$ ls
a.c  a.o  b.c  b.o  libtest.a
mutian@mutian:~/share/test/test$ ar -t libtest.a 
a.o
b.o

 

mutian@mutian:~/share/test/test$ objdump -t libtest.a 
In archive libtest.a:

a.o:     file format elf64-x86-64

SYMBOL TABLE:
0000000000000000 l    df *ABS*    0000000000000000 a.c
0000000000000000 l    d  .text    0000000000000000 .text
0000000000000000 l    d  .data    0000000000000000 .data
0000000000000000 l    d  .bss    0000000000000000 .bss
0000000000000000 l    d  .note.GNU-stack    0000000000000000 .note.GNU-stack
0000000000000000 l    d  .eh_frame    0000000000000000 .eh_frame
0000000000000000 l    d  .comment    0000000000000000 .comment
0000000000000000 g     F .text    0000000000000022 main
0000000000000000         *UND*    0000000000000000 swap


b.o:     file format elf64-x86-64

SYMBOL TABLE:
0000000000000000 l    df *ABS*    0000000000000000 b.c
0000000000000000 l    d  .text    0000000000000000 .text
0000000000000000 l    d  .data    0000000000000000 .data
0000000000000000 l    d  .bss    0000000000000000 .bss
0000000000000000 l    d  .note.GNU-stack    0000000000000000 .note.GNU-stack
0000000000000000 l    d  .eh_frame    0000000000000000 .eh_frame
0000000000000000 l    d  .comment    0000000000000000 .comment
0000000000000000 g     O .data    0000000000000004 shared
0000000000000000 g     F .text    0000000000000014 swap

 

mutian@mutian:~/share/test/test/test$ ls
libtest.a
mutian@mutian:~/share/test/test/test$ ar -t libtest.a 
a.o
b.o
mutian@mutian:~/share/test/test/test$ ar d libtest.a  b.o
mutian@mutian:~/share/test/test/test$ ar -t libtest.a 
a.o

 

mutian@mutian:~/share/test/test/test$ ls
libtest.a
mutian@mutian:~/share/test/test/test$ ar -t libtest.a 
a.o
b.o
mutian@mutian:~/share/test/test/test$ ar -x libtest.a b.o a.o
mutian@mutian:~/share/test/test/test$ ls
a.o  b.o  libtest.a

 

posted @ 2016-04-24 12:04  牧 天  阅读(237)  评论(0)    收藏  举报