Chinaunix首页 | 论坛 | 博客
  • 博客访问: 370738
  • 博文数量: 100
  • 博客积分: 2500
  • 博客等级: 大尉
  • 技术积分: 1209
  • 用 户 组: 普通用户
  • 注册时间: 2011-04-15 21:24
文章分类

全部博文(100)

文章存档

2011年(100)

分类: 系统运维

2011-04-27 21:12:43

参考:

  1. NAME
  2.        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.
print1.c
  1. void
  2. print1(void)
  3. {
  4.         printf("First print\n");
  5. }

print2.c
  1. void
  2. print2(void)
  3. {
  4.         printf("Second print\n");
  5. }

create static lib file:   lib[name].a
  1. gcc -c print1.c print2.c
  2. ar -rsv libprint.a print1.o print2.o

test.c
  1. #include <stdio.h>

  2. int
  3. main(void)
  4. {
  5.         print1();
  6.         print2();

  7.         return 0;
  8. }

use:
  1. gcc -o test test.c -L./ -lprint

  1. -llibrary
  2.       
  3.            Search the library named library when linking.
  4.           
  5.            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


阅读(1435) | 评论(0) | 转发(0) |
0

上一篇:大小端问题

下一篇:动态链接库

给主人留下些什么吧!~~