Linux动态库和静态库基础
来源:互联网 发布:民生证券mac版 编辑:程序博客网 时间:2024/06/06 03:18
example: hello.c hello.h main.c
1.静态库
gcc -c hello.c
ar cr libhello.a hello.o
引用库: -lhello
2.动态库
gcc -c hello.c
gcc -shared -fPCI -o libhello.so hello.o
引用库: -lhello
3.指定头文件
gcc main.c -o main -I include
include:头文件的存放路径
4.指定库文件
gcc main.c -o main -L lib -lhello
lib:库文件的存放路径
5.配置库路径
vi /etc/ld.so.conf
编辑,添加库所在的路径
# ldconfig
重新生成ld.so.cache
6.配置库环境变量
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:./lib
离开终端就失效,可以写入:~/.bashrc 或 ~/.bash_profile 或 /etc/profile
6.查看程序需要的动态库
ldd ./main
6.gcc/g++ 常用选项
-Wall: 打开几乎所有的警告
-Werror:将所有的警告视为错误
-g:产生调试信息
-O1/2/3:优化,有3个级别,一般使用-O2
1.静态库
gcc -c hello.c
ar cr libhello.a hello.o
引用库: -lhello
2.动态库
gcc -c hello.c
gcc -shared -fPCI -o libhello.so hello.o
引用库: -lhello
3.指定头文件
gcc main.c -o main -I include
include:头文件的存放路径
4.指定库文件
gcc main.c -o main -L lib -lhello
lib:库文件的存放路径
5.配置库路径
vi /etc/ld.so.conf
编辑,添加库所在的路径
# ldconfig
重新生成ld.so.cache
6.配置库环境变量
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:./lib
离开终端就失效,可以写入:~/.bashrc 或 ~/.bash_profile 或 /etc/profile
6.查看程序需要的动态库
ldd ./main
6.gcc/g++ 常用选项
-Wall: 打开几乎所有的警告
-Werror:将所有的警告视为错误
-g:产生调试信息
-O1/2/3:优化,有3个级别,一般使用-O2
一般为:-Wall -Werror -O2
7.【注意】:若目录同时存在.a和.so库,那编译器默认会先使用.so动态库,若要使用静态库,只需将.so重命名或者移动到其他目录即可。
- Linux动态库和静态库基础
- Linux动态库和静态库基础
- 【Linux基础】gcc生成静态库和动态库
- Linux动态库、静态库加载基础
- Linux动态库、静态库加载基础
- Linux动态库、静态库加载基础
- 静态库和动态库基础
- linux库:静态库和动态库
- Linux动态库和静态库比较
- Linux创建静态库和动态库
- Linux中的静态库和动态库
- linux 下静态库和动态库
- linux中的动态库和静态库
- [Linux]链接,静态库和动态库
- LINUX 静态库和动态库
- linux静态库和动态库分析
- Linux静态库和动态库
- linux静态库和动态库
- 应用FrameLayout实现遮罩层
- ubuntu下安装adobe Flash
- ubuntu右键添加终端选项
- c语言用指针实现求最大数和最小数的程序
- T-SQL函数 大全
- Linux动态库和静态库基础
- Android 2.3 SD卡挂载流程浅析(六)
- 使用接口还是基类
- C# 制作Com组件:java调用.net DLL的方法
- linux内存管理-20121217
- 无刷新分页前端代码
- lua绑定C++对象学习
- Programming with ATL
- Android设备10大不应忽略的功能