gcc编译流程:
test.c---->test.cxx(预编译)---->test.s(asm文件)---->test.o(obj文件)--->test(exe) (-E) (-S) (-c) 链接---test.c
| ----test_a.cproject-| | ---h_test.h---|---test_b.c | ----test_c.ctest.c:
#include "so_test.h"int main(){test_a();test_b();test_c();return 0;}
h_test.h
1 //so_test.h 2 #include "stdio.h"3 void test_a();4 void test_b();5 void test_c();
test_a.c
1 //test_a.c 2 #include "so_test.h"3 void test_a()4 {5 printf("this is in test_a...\n");6 }
test_b.c
1 //test_b.c 2 #include "so_test.h"3 void test_b()4 {5 printf("this is in test_b...\n");6 }
test_c.c
//test_c.c #include "so_test.h"void test_c(){printf("this is in test_c...\n");}
(1)gcc编译动态库gcc test_a.c test_b.c test_c.c -fPIC -share libtest.sogcc test.c -L . -ltest -o test./test
(2)gcc编译静态库
gcc -c test_a.c test_b.c test_c.c
ar -rv libtest.a test_a.o test_b.o test_c.o(打包)gcc test.c -L . -ltest -static -o test2./test2