creating hello
-rpath項負責添加運行時庫路徑,否則只能手工修改LD_LIBRARY_PATH環境變量了。
驗證一下:
# ldd .libs/hello
linux-gate.so.1 => (0xffffe000)
libhello.so.0 => /usr/local/lib/libhello.so.0 (0x40019000)
libc.so.6 => /lib/tls/libc.so.6 (0x40031000)
/lib/ld-linux.so.2 (0x40000000)
5.install executable file
#libtool --mode=install cp hello /usr/local/bin/hello
安裝可執行程序。
6.運行
libtool --mode=execute hello
或直接運行hello
注意:此處hello已經安裝在/usr/local/bin下了,可以用which hello來查看
【附】源碼
foo.c
#include <stdio.h>
char msg[128]="Hello world";
void print()
{
printf("%s\n", msg);
}
hello.c:
extern char msg[128];
extern void print();
int main()
{
print();
}
Makefile:
LO_OBJS = foo.lo
PACKAGE_VERSION = 1:1:1
LIBDIR=/usr/local/lib
BINDIR=/usr/local/bin
all : hello
install : libhello.la hello
libtool --mode=install install -c libhello.la
${LIBDIR}/libhello.la
libtool --mode=install cp hello ${BINDIR}/hello
uninstall : ${LIBDIR}/libhello.la ${BINDIR}/hello
libtool --mode=uninstall /bin/rm ${LIBDIR}/libhello.la
libtool --mode=uninstall /bin/rm ${BINDIR}/hello
hello : libhello.la hello.lo
libtool --mode=install install -c libhello.la ${LIBDIR}/libhello.la
libtool --mode=link gcc -g -O -o hello hello.lo -rpath ${LIBDIR} libhello.la
libhello.la : $(LO_OBJS)
libtool --mode=link --tag=CC gcc -g -O -o libhello.la $(LO_OBJS) -rpath ${LIBDIR} -version-info ${PACKAGE_VERSION}
foo.lo : foo.c
libtool --mode=compile gcc -g -O -c foo.c
hello.lo : hello.c
libtool --mode=compile gcc -g -O -c hello.c
clean :
rm -f lib*.a *~ *core *.lo *.o *.la hello
rm -rf .libs
這樣,用戶可以用make編譯,make install/uninstall安裝/卸載,make clean清除編譯臨時文件,安裝成功後,可以直接執行hello,不必指明路徑也不必再另設環境變量LD_LIBRARY_PATH,非常方便!
libtool的作用及應用
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章
[libtool] autogen時AM_PATH_GLIB_2_0錯誤的處理
lieberstraum
2020-02-23 06:00:41
使用 GNU Libtool 創建庫[轉載]
jimmee
2020-02-22 16:40:55
使用 GNU Libtool 創建庫
js0huang
2020-02-20 18:33:16
libtool : X--tag=CC: command not found 錯誤
feizhijiang
2018-09-01 17:16:25
make: ./libtool:command not found
admithhq
2018-08-22 13:56:39