linux如何生成so文件,新人问个问题,莫见笑:关于如何生成so文件,大家多多捧场啊...
kilisky 于 2008-05-26 12:29:18發表:
你沒有安裝庫,當然看不到.so了,安裝了才可以看的到的。
make DESTDIR=安裝目錄 install
進入安裝目錄里看lib,就有了.
黃富強 于 2008-05-14 18:24:13發表:
才明白你的意思,研究一下這里面的
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 : 編譯的目標文件
.a : 靜態庫,其實就是把若干o文件打了個包
.so : 動態鏈接庫(共享庫)
.lo : 使用libtool編譯出的目標文件,其實就是在o文件中添加了一些信息
.la : 使用libtool編譯出的庫文件,其實是個文本文件,記錄同名動態庫和靜態庫的相關信息
la只有在用libtool編譯應用程序或庫時才用,即開發者只指明la文件,至于最終鏈接a還是so由libtool決定,不使用libtool的小程序用不上la, so是直接用特殊編譯參數編譯出來的,注意路徑的問題.
其它實現方法:http://linux.chinaunix.net/bbs/thread-959710-1-1.html
[本帖最后由 黃富強 于 2008-5-14 19:28 編輯]
muyizhu 于 2008-05-14 14:19:04發表:
自己頂一下
muyizhu 于 2008-05-14 13:28:11發表:
謝謝強哥了
muyizhu 于 2008-05-14 13:26:48發表:
還是不行啊,參考的價值不大
我這邊文件可能會很多,所以最好是用libtool
那以下是我的過程:(假設只有一個文件add.c放在test文件夾下,想生成一個libtest.so)
**********add.c********************
#include "stdlib.h"
int add(int num1,int num2)
{
return (int)(num1+num2);
}
************************************
1. 進入到test下執行autoscan生成configure.scan,改文件名為configure.in,并作適當修改
2.執行aclocal生成aclocal.m4
3.執行autoheader
4. 編寫Makefile.am(使用libtool)
**************Makefile.am**************
AUTOMAKE_OPTIONS = foreign
lib_LTLIBRARIES = libtest.la
libtest_la_SOURCES = add.c
*****************************************
5.執行automake --add-missing
6. autoconf
7. ./configure
8. make
上面就是一般自動生成makefile的過程
我看網上有些人就是這么介紹通過libtool生成libtest.so的
可我make之后libtest.la是生成了,就是沒找到libtest.so這個文件
我想問的是怎么生成libtest.so
是不是makefile.am還需要做什么修改
muyizhu 于 2008-05-14 12:32:47發表:
又或者不用libtool
這個makefile.am需要怎么寫
muyizhu 于 2008-05-14 12:31:32發表:
我看網上有介紹到用libtool
結果libtest.la是生成了,但是libtest.so沒有生成
是不是這個makefile.am需要做什么修改
muyizhu 于 2008-05-14 12:29:15發表:
謝謝指教
可是直接用GCC我也知道怎么用
問題是我想自動生成makefile
自動生成過程中的makefile.am我不知道怎么寫
黃富強 于 2008-05-14 12:06:14發表:
gcc a.c b.c c.c -fPIC -shared -o libtest.so
動態鏈接庫相當于Windows中用的DLL
研究一下基本GCC使用方法,sou一下,很多.
[本帖最后由 黃富強 于 2008-5-14 12:10 編輯]
總結
以上是生活随笔為你收集整理的linux如何生成so文件,新人问个问题,莫见笑:关于如何生成so文件,大家多多捧场啊...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 《原神》4.8板砖抽取建议
- 下一篇: 《三国:谋定天下》郭图诸葛亮袁绍阵容玩法