linux如何生成so文件,新人问个问题,莫见笑:关于如何生成so文件,大家多多捧场啊...
kilisky 于 2008-05-26 12:29:18發(fā)表:
你沒(méi)有安裝庫(kù),當(dāng)然看不到.so了,安裝了才可以看的到的。
make DESTDIR=安裝目錄 install
進(jìn)入安裝目錄里看lib,就有了.
黃富強(qiáng) 于 2008-05-14 18:24:13發(fā)表:
才明白你的意思,研究一下這里面的
http://www.gnu.org/software/libtool/manual/automake/Hello-World.html#Hello-World
http://www.gnu.org/software/libtool/manual/html_node/index.html
fuqiang@fuqiang-laptop:~$ 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
--finish same as `--mode=finish'
--help display this help message and exit
--mode=MODE use operation mode MODE [default=inferred from MODE-ARGS]
--quiet same as `--silent'
--silent don't print informational messages
--tag=TAG use configuration variables from tag TAG
--version print version information
MODE 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 directory
MODE-ARGS vary depending on the MODE. Try `libtool --help --mode=MODE' for
a more detailed description of MODE.
Report bugs to .
.o : 編譯的目標(biāo)文件
.a : 靜態(tài)庫(kù),其實(shí)就是把若干o文件打了個(gè)包
.so : 動(dòng)態(tài)鏈接庫(kù)(共享庫(kù))
.lo : 使用libtool編譯出的目標(biāo)文件,其實(shí)就是在o文件中添加了一些信息
.la : 使用libtool編譯出的庫(kù)文件,其實(shí)是個(gè)文本文件,記錄同名動(dòng)態(tài)庫(kù)和靜態(tài)庫(kù)的相關(guān)信息
la只有在用libtool編譯應(yīng)用程序或庫(kù)時(shí)才用,即開(kāi)發(fā)者只指明la文件,至于最終鏈接a還是so由libtool決定,不使用libtool的小程序用不上la, so是直接用特殊編譯參數(shù)編譯出來(lái)的,注意路徑的問(wèn)題.
其它實(shí)現(xiàn)方法:http://linux.chinaunix.net/bbs/thread-959710-1-1.html
[本帖最后由 黃富強(qiáng) 于 2008-5-14 19:28 編輯]
muyizhu 于 2008-05-14 14:19:04發(fā)表:
自己頂一下
muyizhu 于 2008-05-14 13:28:11發(fā)表:
謝謝強(qiáng)哥了
muyizhu 于 2008-05-14 13:26:48發(fā)表:
還是不行啊,參考的價(jià)值不大
我這邊文件可能會(huì)很多,所以最好是用libtool
那以下是我的過(guò)程:(假設(shè)只有一個(gè)文件add.c放在test文件夾下,想生成一個(gè)libtest.so)
**********add.c********************
#include "stdlib.h"
int add(int num1,int num2)
{
return (int)(num1+num2);
}
************************************
1. 進(jìn)入到test下執(zhí)行autoscan生成configure.scan,改文件名為configure.in,并作適當(dāng)修改
2.執(zhí)行aclocal生成aclocal.m4
3.執(zhí)行autoheader
4. 編寫(xiě)Makefile.am(使用libtool)
**************Makefile.am**************
AUTOMAKE_OPTIONS = foreign
lib_LTLIBRARIES = libtest.la
libtest_la_SOURCES = add.c
*****************************************
5.執(zhí)行automake --add-missing
6. autoconf
7. ./configure
8. make
上面就是一般自動(dòng)生成makefile的過(guò)程
我看網(wǎng)上有些人就是這么介紹通過(guò)libtool生成libtest.so的
可我make之后libtest.la是生成了,就是沒(méi)找到libtest.so這個(gè)文件
我想問(wèn)的是怎么生成libtest.so
是不是makefile.am還需要做什么修改
muyizhu 于 2008-05-14 12:32:47發(fā)表:
又或者不用libtool
這個(gè)makefile.am需要怎么寫(xiě)
muyizhu 于 2008-05-14 12:31:32發(fā)表:
我看網(wǎng)上有介紹到用libtool
結(jié)果libtest.la是生成了,但是libtest.so沒(méi)有生成
是不是這個(gè)makefile.am需要做什么修改
muyizhu 于 2008-05-14 12:29:15發(fā)表:
謝謝指教
可是直接用GCC我也知道怎么用
問(wèn)題是我想自動(dòng)生成makefile
自動(dòng)生成過(guò)程中的makefile.am我不知道怎么寫(xiě)
黃富強(qiáng) 于 2008-05-14 12:06:14發(fā)表:
gcc a.c b.c c.c -fPIC -shared -o libtest.so
動(dòng)態(tài)鏈接庫(kù)相當(dāng)于Windows中用的DLL
研究一下基本GCC使用方法,sou一下,很多.
[本帖最后由 黃富強(qiáng) 于 2008-5-14 12:10 編輯]
總結(jié)
以上是生活随笔為你收集整理的linux如何生成so文件,新人问个问题,莫见笑:关于如何生成so文件,大家多多捧场啊...的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 《原神》4.8板砖抽取建议
- 下一篇: linux怎么看日期,linux 怎么用