Linux的Terminal中如何生成静态库以及如何使用静态库
来源:互联网 发布:餐厅收银软件 免费 编辑:程序博客网 时间:2024/06/07 03:25
Linux的Terminal中如何生成静态库以及如何使用静态库
生成静态库文件分为两个步骤
hello.c
#include<stdio.h>void hello(){printf("hello\n");}
main.c
#include<stdio.h>#include"hello.h"int main(){printf("Hello main\n");hello();return 0;}
- 生成目标文件—hello.o
root@ubuntu:~/lesson/chap2/2-6/tmp# gcc -o hello.o -c hello.c
root@ubuntu:~/lesson/chap2/2-6/tmp# ls
hello.c hello.h hello.o main.c makefile
只编译不链接. - 链接为静态库文件
root@ubuntu:~/lesson/chap2/2-6/tmp# ar rcs libhello.a hello.o
root@ubuntu:~/lesson/chap2/2-6/tmp# ls
hello.c hello.h hello.o libhello.a main.c makefile
其中,生成的静态库libhello.a中的前缀为lib 后缀为.a 文件名为hello.
使用库
用gcc生成可执行文件(编译main.c)
root@ubuntu:~/lesson/chap2/2-6/tmp# gcc -o test main.c -L./ -lhello
root@ubuntu:~/lesson/chap2/2-6/tmp# ls
hello.c hello.h hello.o libhello.a main.c makefile test
root@ubuntu:~/lesson/chap2/2-6/tmp# ./test
Hello main
hello
其中,指定库路径(./当前路径)为:-L库路径
指定库文件为(libhello.a): `-l库名称““
gcc -o test main.c -L./ -lhello
**makefile 生成静态库,并且使用静态库.**makefile:.PHONY:cleanlibmath:libmath.o ar rcs $@ $^libmath.o:libmath.c libmath.hclean: rm libmath.a libmath.olibmath.c:
void libmath_init()
{
printf(“libmath_init …\n”);
}“`
阅读全文
0 0
- Linux的Terminal中如何生成静态库以及如何使用静态库
- Linux的Terminal中如何生成动态库以及如何使用动态库
- 如何生成c语言静态库以及链接静态库
- Linux 如何使用gcc生成静态库和动态库
- linux如何使用gcc生成静态库和动态库
- Linux下如何生成和使用动静态库
- Vs2005生成静态库,及如何使用这个静态库
- Linux下静态库的生成以及使用实例图解
- Linux下静态库的生成以及使用实例图解
- linux中静态库和动态库的生成以及使用
- vc++项目中如何使用静态库
- Linux 创建静态库以及静态库的使用
- Linux 创建静态库以及静态库的使用
- linux静态库的生成与使用
- linux静态库的生成与使用
- linux静态库的生成与使用
- linux静态库的生成与使用
- Linux静态库的生成和使用
- 备忘:Hibernate5中调用存储过程
- jdk版本不兼容解决
- 无我编程的十大戒律
- OPTICS:通过点排序识别聚类结构的密度聚类算法
- java多线程共同工作,利用synchronized关键字
- Linux的Terminal中如何生成静态库以及如何使用静态库
- 开发者论坛一周精粹(第二十期) :晒往期云栖大会的照片或感想,赢2017杭州云栖大会门票
- FloatingActionButton的使用
- 【Android四大组件】bundle通信
- Java内存
- python 列表
- Static关键字
- 2017暑假集训感悟
- XSS检测Java源码