静态链接库
? ? ? ? ? ? ? 靜態鏈接庫:編譯時就完成鏈接過程,文件名擴展名為.a
?
[xxx@localhost staticLibrary]$ ls main.c test.c test.h [mapan@localhost staticLibrary]$ ls main.c test.c test.h [xxx@localhost staticLibrary]$ cat main.c #include<stdio.h> #include"test.h"int main() {int num=test(2,3);printf("num=%d\n",num);return 0; } [xxx@localhost staticLibrary]$ cat test.c #include"test.h"int test(int a,int b) { return a*b; } [xxx@localhost staticLibrary]$ cat test.h int test(int a,int b);[xxx@localhost staticLibrary]$?
再看:
?
[xxx@localhost staticLibrary]$ gcc -c test.c [xxx@localhost staticLibrary]$ ls main.c test.c test.h test.o [xxx@localhost staticLibrary]$ ar cr libtest.a test.o [xxx@localhost staticLibrary]$ ls libtest.a main.c test.c test.h test.o [xxx@localhost staticLibrary]$?
調用靜態庫:
?
[xxx@localhost staticLibrary]$ gcc main.c -L. -ltest [xxx@localhost staticLibrary]$ ls a.out libtest.a main.c test.c test.h test.o [xxx@localhost staticLibrary]$ ./a.out num=6 [xxx@localhost staticLibrary]$?
查看庫信息:
?
[xxx@localhost staticLibrary]$ ar tv libtest.a rw-rw-r-- 511/511 1240 Jul 26 19:52 2017 test.o [xxx@localhost staticLibrary]$一個靜態鏈接庫可以由多個.o文件組成。
?
?
?
?
總結
- 上一篇: big endian and littl
- 下一篇: gcc与__cplusplus宏