From 06c95ae1a10efb14c1dd6babb4815ff2112dc492 Mon Sep 17 00:00:00 2001 From: flykhan Date: Wed, 12 Jul 2023 10:38:10 +0800 Subject: [PATCH] =?UTF-8?q?day8=20coding:=20=E9=9D=99=E6=80=81=E5=BA=93?= =?UTF-8?q?=E7=9A=84=E7=94=9F=E6=88=90=E5=92=8C=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- day8/d1/README.md | 17 +++++++++++++++++ day8/d1/my/includes/my.h | 9 +++++++++ day8/d1/my/libs/libmy.a | Bin 0 -> 1492 bytes day8/d1/test.c | 9 +++++++++ 4 files changed, 35 insertions(+) create mode 100644 day8/d1/README.md create mode 100644 day8/d1/my/includes/my.h create mode 100644 day8/d1/my/libs/libmy.a create mode 100644 day8/d1/test.c 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 0000000000000000000000000000000000000000..a35fcdb18c0928f7635f70610100bb0a0f088da7 GIT binary patch literal 1492 zcmbtUO=}Zj5S~qHtWirWJqY!%y=cYub+=6ylu}m08WBH040s9cCfyRSn?QCK+JYY^ zA@t%8@Zf*xAMj5I9`&||fX?i`6UXg((Ffk0nPtM13(4WD_T(!LX`9%JXRxFa~6(uWhJNC%sSbdS~2(P@4P1uD~5sPau~1!zb$3~ z-cwf%HRQsYbaOmN=xj+b`NpxtWSH&;8oWEdyrmTD?% z-AOXberr3*YASoCFICvnM&9QAJM~s&Ju<#^~B#__=dD zMJ|f{@IBFh5YKjYcFM*f>EpEI69ZrphoEN_PYW)Q2M{@-+?1)a~L*#8%EC~$26 literal 0 HcmV?d00001 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