day8 coding: 静态库的生成和使用
This commit is contained in:
parent
ff10f99477
commit
06c95ae1a1
|
@ -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
|
||||
```
|
|
@ -0,0 +1,9 @@
|
|||
#ifndef __MY_H__
|
||||
#define __MY_H__
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
extern int sum(int, int);
|
||||
extern int sub(int, int);
|
||||
|
||||
#endif
|
Binary file not shown.
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue