linux下.a/.so/.la目标库区别
在linux平台上编译时,常会遇到目标库的疑问,有静态库也有动态库,单个理解都不太难,但是对复杂的工程而言,一旦混合到一起去,对整个工程的理解和调用,将会造成很大困扰,本文就汇总这几种常见编译结果文件的区别。
一、格式说明
linux下编译,常会遇到后缀为:.o .so .a .la .ko等格式文件,尽管linux并不以扩展名作为识别文件格式的唯一依据,但规范约定还是有的,如下:
- .o 是目标对象文件,相当于windows中的.obj文件
- .a 为静态库,可以是一个或多个.o合在一起,用于静态连接
- .la 为libtool生成的共享库,其实是个配置文档。可以用$file *.la查看*.la文件,或用vi来查看。
- .so 为共享库,类似windows平台的dll文件
补充: 还有一种扩展名为.ko 文件,不过它是Linux内核使用的动态链接文件后缀,属于模块文件,用来在Linux系统启动时加载内核模块。
二、创建实例
1、创建.o对象文件
$ gcc -c test.c
生成test.o,跳过链接对象,所以不是可执行文件。
2、创建.a静态库文件
$ ar -r libtest.a test1.o test2.o
3、创建动态库.so
$ gcc -Wall -fpic -shared test1.c test2.c -o libtest.so
上一句执行,将test1.c和test2.c编译生成动态库文件libtest.so
4、链接库文件
$ gcc -Wall -fpic -shared -Ltest test3.c -o libtest.so
编译test3.c后并与静态libtest.a链接(默认会到/usr/lib下找该文件)生成libtest.so动态库。
5、生成.la库
.la库一般通过makefile进行,当然也可以通过命令行进行,参考命令:
$libtool --mode=link gcc -o libmylib.la -rpath /usr/lib –L/usr/lib –la
libtool将会搜索libmylib.a文件,并传家libmylib.la。更多libtool帮助如下:
Tst@Tst-PC /cygdrive/d/ $ libtool --help Usage: libtool [OPTION]... [MODE-ARG]...Provide generalized library-building support services.--config show all configuration variables --debug enable verbose shell tracing -n, --dry-run display commands without modifying any files --features display basic configuration information and exit --mode=MODE use operation mode MODE --preserve-dup-deps don't remove duplicate dependency libraries --quiet, --silent don't print informational messages --no-quiet, --no-silent print informational messages (default) --tag=TAG use configuration variables from tag TAG -v, --verbose print more informational messages than default --no-verbose don't print the extra informational messages --version print version information -h, --help, --help-all print short, long, or detailed help messageMODE must be one of the following:clean remove files from the build directory compile compile a source file into a libtool object execute automatically set library path, then run a program finish complete the installation of libtool libraries install install libraries or executables link create a library or an executable uninstall remove libraries from an installed directoryMODE-ARGS vary depending on the MODE. When passed as first option, `--mode=MODE' may be abbreviated as `MODE' or a unique abbreviation of that. Try `libtool --help --mode=MODE' for a more detailed description of MODE.When reporting a bug, please describe a test case to reproduce it and include the following information:host-triplet: i686-pc-cygwin shell: /bin/sh compiler: gcc compiler flags: -g -O2 -pipe linker: /usr/i686-pc-cygwin/bin/ld.exe (gnu? yes) libtool: (GNU libtool) 2.4 automake: automake (GNU automake) 1.11.1 autoconf: autoconf (GNU Autoconf) 2.68Report bugs to <bug-libtool@gnu.org>. GNU libtool home page: <http://www.gnu.org/software/libtool/>. General help using GNU software: <http://www.gnu.org/gethelp/>.
参考资料:
http://wiki.ubuntu.org.cn/index.php?title=Compiling_C&variant=zh-hans
http://afreez.blog.51cto.com/59057/7338
http://blog.csdn.net/lhf_tiger/article/details/7065289
http://topic.csdn.net/u/20080124/13/c34ece2c-81a0-4818-bec4-d705aa4aecb1.html
linux下.a/.so/.la目标库区别相关推荐
- linux下.a/.so/.la目标库区别-转
在linux平台上编译时,常会遇到目标库的疑问,有静态库也有动态库,单个理解都不太难,但是对复杂的工程而言,一旦混合到一起去,对整个工程的理解和调用,将会造成很大困扰,本文就汇总这几种常见编译结果文件 ...
- spdlog linux编译出错,Linux下编写Makefile引入第三方库
Linux下编写Makefile引入第三方库 前言:一直在使用CmakaList 生成Makefile文件,其实很少去写Makefile,但是最近帮朋友处理了一个Makefile引入第三方库的问题,就 ...
- Linux下安装和使用boost库
Linux下安装和使用boost库 2016-08-26 20:29:06 zhaomax 阅读数 349更多 分类专栏: C++ 用boost库中的serialization库.Boost库分为两个 ...
- Linux下su与su -命令的区别
Linux下su与su -命令的区别 在启动服务器ntpd服务时遇到一个问题 使用 su root 切换到root用户后,不可以使用service命令: 使用 su - 后,就可以使用service命 ...
- Linux下deb包和rpm包区别
linux安装软件的三种方式 deb,rpm,yum,apt-get安装 源码编译安装 二进制安装 Linux下deb包和rpm包区别 有的系统只支持使用rpm包安装,有的只支持deb包安装,混乱安装 ...
- Linux zip 7z效率比较,linux 下面的 7z和7za的区别
linux 下面的 7z和7za的区别,区别参照下面的man文件: 7z(1) 7z(1) NAME 7z - A file archiver with highest compression rat ...
- Linux下V4L2框架基于SDL库本地USB摄像头监控
Linux下V4L2框架基于SDL库本地USB摄像头监控 1.摄像头框架编程步骤 (1)打开摄像头设备(/dev/video0 ./dev/video1 ) (2)设置图像格式:VIDIOC_S_FM ...
- linux cp mv区别,浅谈Linux下mv和cp命令的区别
1.功能上的区别 mv:用户可以使用该命令为文件或目录重命名或将文件由一个目录移入另一个目录中. cp: 该命令的功能是将给出的文件或目录拷贝到另一文件或目录中. 2.从inode角度来区分 mv:会 ...
- Linux下CST和UTC时间的区别以及不一致的解决方法
1.在linux中,用date查看时间的时候显示: 2013年 2月 17日 星期三 19:04:14 CST 世界协调时间(Universal Time Coordinated,UTC): GPS ...
最新文章
- 为什么在把多维数组传递给函数时必须要指定除第一维之外的其他维
- history linux 日志服务器_Linux下使用rsyslog部署日志服务器 记录history并发送到rsyslog服务器...
- md5会重复吗_自媒体平台视频重复审查机制,如何避免自己做的视频和别人的重复...
- SAP Spartacus storefront.component.html 怎么关联到其他的页面
- SpringBoot 配置记录
- UITableView 系列四 :项目中行的操作 (添加移动和删除)(实例)
- python正则表达式怎么表示零个或多个字符_VBA中正则表达式之分组
- javascript判断日期奇偶_js中判断奇数或偶数
- MySQL:浅析 Impossible WHERE noticed after reading const tables
- Java中数字朝着0.5的倍数取舍
- 创建项目连接错误_EF6连接Postgresql数据库
- E - Game 树上dfs贪心
- 有Pytz时区列表吗?
- mysql查询登录端口_mysql查看、修改端口、指定端口登录
- 第四章—密钥管理与分配
- 做外贸十大不能接的订单!
- 腾讯广告设计大赛初探
- NPDP知识推送-第七章产品生周期管理(1)
- Jupyter使用技巧+快捷键【速查手册】
- 地区数据erea.js