日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > linux >内容正文

linux

linux下.a/.so/.la目标库区别

發(fā)布時(shí)間:2023/12/19 linux 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux下.a/.so/.la目标库区别 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

在linux平臺(tái)上編譯時(shí),常會(huì)遇到目標(biāo)庫(kù)的疑問,有靜態(tài)庫(kù)也有動(dòng)態(tài)庫(kù),單個(gè)理解都不太難,但是對(duì)復(fù)雜的工程而言,一旦混合到一起去,對(duì)整個(gè)工程的理解和調(diào)用,將會(huì)造成很大困擾,本文就匯總這幾種常見編譯結(jié)果文件的區(qū)別。

一、格式說(shuō)明

linux下編譯,常會(huì)遇到后綴為:.o .so .a .la .ko等格式文件,盡管linux并不以擴(kuò)展名作為識(shí)別文件格式的唯一依據(jù),但規(guī)范約定還是有的,如下:

  • .o 是目標(biāo)對(duì)象文件,相當(dāng)于windows中的.obj文件
  • .a 為靜態(tài)庫(kù),可以是一個(gè)或多個(gè).o合在一起,用于靜態(tài)連接
  • .la 為libtool生成的共享庫(kù),其實(shí)是個(gè)配置文檔。可以用$file *.la查看*.la文件,或用vi來(lái)查看。
  • .so 為共享庫(kù),類似windows平臺(tái)的dll文件

補(bǔ)充: 還有一種擴(kuò)展名為.ko 文件,不過(guò)它是Linux內(nèi)核使用的動(dòng)態(tài)鏈接文件后綴,屬于模塊文件,用來(lái)在Linux系統(tǒng)啟動(dòng)時(shí)加載內(nèi)核模塊。

二、創(chuàng)建實(shí)例

1、創(chuàng)建.o對(duì)象文件

$ gcc -c test.c

生成test.o,跳過(guò)鏈接對(duì)象,所以不是可執(zhí)行文件。

2、創(chuàng)建.a靜態(tài)庫(kù)文件

$ ar -r libtest.a test1.o test2.o

3、創(chuàng)建動(dòng)態(tài)庫(kù).so

$ gcc -Wall -fpic -shared test1.c test2.c -o libtest.so

上一句執(zhí)行,將test1.c和test2.c編譯生成動(dòng)態(tài)庫(kù)文件libtest.so

4、鏈接庫(kù)文件

$ gcc -Wall -fpic -shared -Ltest test3.c -o libtest.so

編譯test3.c后并與靜態(tài)libtest.a鏈接(默認(rèn)會(huì)到/usr/lib下找該文件)生成libtest.so動(dòng)態(tài)庫(kù)。

5、生成.la庫(kù)

.la庫(kù)一般通過(guò)makefile進(jìn)行,當(dāng)然也可以通過(guò)命令行進(jìn)行,參考命令:

$libtool --mode=link gcc -o libmylib.la -rpath /usr/lib –L/usr/lib –la

libtool將會(huì)搜索libmylib.a文件,并傳家libmylib.la。更多l(xiāng)ibtool幫助如下:

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

總結(jié)

以上是生活随笔為你收集整理的linux下.a/.so/.la目标库区别的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。