diff --git a/day8/d1/README.md b/day8/d1/README.md new file mode 100644 index 0000000..250ff25 --- /dev/null +++ b/day8/d1/README.md @@ -0,0 +1,17 @@ +### 静态库生成 + +```bash +# 汇编源文件 xxx.c ---> xxx.o +gcc -c xxx.c -o xxx.o +# 使用汇编后的源文件生成静态库 xxx.o ---> libxxx.a +ar rc libxxx.a xxx.o +``` + +### 静态库的使用 + +```bash +# 生成可执行文件 a.out +gcc -static test.c -L/home/.../libs -lxxx -I/home/.../includes +# 生成自定义可执行文件 test +gcc -static test.c -o test -L/home/.../libs -lxxx -I/home/.../includes +``` diff --git a/day8/d1/my/includes/my.h b/day8/d1/my/includes/my.h new file mode 100644 index 0000000..9310404 --- /dev/null +++ b/day8/d1/my/includes/my.h @@ -0,0 +1,9 @@ +#ifndef __MY_H__ +#define __MY_H__ + +#include + +extern int sum(int, int); +extern int sub(int, int); + +#endif \ No newline at end of file diff --git a/day8/d1/my/libs/libmy.a b/day8/d1/my/libs/libmy.a new file mode 100644 index 0000000..a35fcdb Binary files /dev/null and b/day8/d1/my/libs/libmy.a differ diff --git a/day8/d1/test.c b/day8/d1/test.c new file mode 100644 index 0000000..fe77231 --- /dev/null +++ b/day8/d1/test.c @@ -0,0 +1,9 @@ +#include "./my/includes/my.h" + +int main() +{ + int a = 10, b = 20; + printf("10+20=%d\n", sum(a, b)); + printf("20-10=%d\n", sub(b, a)); + return 0; +} \ No newline at end of file