libtool如何使用

Posted on 2011年12月27日 14:54

在不同的系统中建立动态链接库的方法有很大的差别,这主要是因为每个系统对动态链接库的看法和实现并不相同,以及编译器对动态链接库支持的选项也不太一样。对于开发人员,如果尝试将使用动态库的软件在这些系统之间移植,需要参考枯涩难懂的系统手册,以及修改相应的 Makefile,这一工作是乏味的,并且具有一定的难度。

使用 GNU Libtool 可以容易的在不同的系统中建立动态链接库。它通过一个称为 Libtool 库的抽象,隐藏了不同系统之间的差异,给开发人员提供了一致的的接口。对于大部分情况,开发人员甚至不用去查看相应的系统手册,只需要掌握 GNU Libtool 的用法就可以了。并且,使用 Libtool 的 Makefile 也只需要编写一次就可以在多个系统上使用。

可以认为libtool是gcc的一个抽象,其包装了gcc(或者其他的编译器),用户无需知道细节,只要告诉libtool需要编译哪些库即可,libtool将处理库的依赖等细节。

例子:

$cat bootstrap
#! /bin/sh
# Run this script to setup the automake environment.
# ./configure
# make
# make install

libtoolize --force --copy
aclocal
autoconf
automake --add-missing
automake

touch src/cmdline.c
touch src/cmdline.h
touch src/cmdline.ggo

$sh bootstrap
bootstrap: 7: libtoolize: not found
configure.in:19: warning: macro `AM_PROG_LIBTOOL' not found in library
bstring/Makefile.am:2: Libtool library used but `LIBTOOL' is undefined
bstring/Makefile.am:2:   The usual way to define `LIBTOOL' is to add `AC_PROG_LIBTOOL'
bstring/Makefile.am:2:   to `configure.in' and run `aclocal' and `autoconf' again.
bstring/Makefile.am:2:   If `AC_PROG_LIBTOOL' is in `configure.in', make sure
bstring/Makefile.am:2:   its definition is in aclocal's search path.
json/Makefile.am:1: Libtool library used but `LIBTOOL' is undefined
json/Makefile.am:1:   The usual way to define `LIBTOOL' is to add `AC_PROG_LIBTOOL'
json/Makefile.am:1:   to `configure.in' and run `aclocal' and `autoconf' again.
json/Makefile.am:1:   If `AC_PROG_LIBTOOL' is in `configure.in', make sure
json/Makefile.am:1:   its definition is in aclocal's search path.
src/Makefile.am:79: SUBDIRS was already defined in condition TRUE, which includes condition WITH_MATRIXSSL_CLI and WITH_MATRIXSSL ...
src/Makefile.am:3: ... `SUBDIRS' previously defined here
src/Makefile.am:151: pkglibdir was already defined in condition TRUE, which includes condition WITH_MODULES ...
/usr/share/automake-1.11/am/header-vars.am: ... `pkglibdir' previously defined here
src/Makefile.am:17: Libtool library used but `LIBTOOL' is undefined
src/Makefile.am:17:   The usual way to define `LIBTOOL' is to add `AC_PROG_LIBTOOL'
src/Makefile.am:17:   to `configure.in' and run `aclocal' and `autoconf' again.
src/Makefile.am:17:   If `AC_PROG_LIBTOOL' is in `configure.in', make sure
src/Makefile.am:17:   its definition is in aclocal's search path.
bstring/Makefile.am:2: Libtool library used but `LIBTOOL' is undefined
bstring/Makefile.am:2:   The usual way to define `LIBTOOL' is to add `AC_PROG_LIBTOOL'
bstring/Makefile.am:2:   to `configure.in' and run `aclocal' and `autoconf' again.
bstring/Makefile.am:2:   If `AC_PROG_LIBTOOL' is in `configure.in', make sure
bstring/Makefile.am:2:   its definition is in aclocal's search path.
json/Makefile.am:1: Libtool library used but `LIBTOOL' is undefined
json/Makefile.am:1:   The usual way to define `LIBTOOL' is to add `AC_PROG_LIBTOOL'
json/Makefile.am:1:   to `configure.in' and run `aclocal' and `autoconf' again.
json/Makefile.am:1:   If `AC_PROG_LIBTOOL' is in `configure.in', make sure
json/Makefile.am:1:   its definition is in aclocal's search path.
src/Makefile.am:79: SUBDIRS was already defined in condition TRUE, which includes condition WITH_MATRIXSSL_CLI and WITH_MATRIXSSL ...
src/Makefile.am:3: ... `SUBDIRS' previously defined here
src/Makefile.am:151: pkglibdir was already defined in condition TRUE, which includes condition WITH_MODULES ...
/usr/share/automake-1.11/am/header-vars.am: ... `pkglibdir' previously defined here
src/Makefile.am:17: Libtool library used but `LIBTOOL' is undefined
src/Makefile.am:17:   The usual way to define `LIBTOOL' is to add `AC_PROG_LIBTOOL'
src/Makefile.am:17:   to `configure.in' and run `aclocal' and `autoconf' again.
src/Makefile.am:17:   If `AC_PROG_LIBTOOL' is in `configure.in', make sure
src/Makefile.am:17:   its definition is in aclocal's search path.


-------------------解决办法----------------------------
安装libtool_2.2.6a-4_i386.deb libltdl-dev_2.2.6a-4_i386.deb 即可

安装:
一般配置好 /etc/apt/source.list里面地址即可.
过时的包在在http://packages.ubuntu.com/页面中可以搜索.
在http://old-releases.ubuntu.com/中也可以找找.
找到后下载到本地, 用
dpkg -i *.deb 安装

 

Libtool相关的文档:

http://www.ibm.com/developerworks/cn/aix/library/1007_wuxh_libtool/index.html

http://www.gnu.org/software/libtool/manual

http://apps.hi.baidu.com/share/detail/17423570

http://www.delorie.com/gnu/docs/libtool/libtool_toc.html