Libtool简介
不同Unix平台,共享库的编译、命名、管理方式不相同
库的命名:.so/.a/.sa/.o
有的平台支持动态加载、有的平台提供其它机制、有的不提供
Libtool对库进行抽象,生成.la形式,支持不同平台
Libtool包
包含libtool和libtoolize两个工具
使用libtool之前,先使用libtoolize,生成本地化的libtool
Libtool的选项
–tag选项
语言 | Tag名称 | 备注 |
---|
C | CC |
|
C++ | CXX |
|
JAVA | GCJ |
|
Go | GO |
|
Fortran | FC |
|
Fortran 77 | F77 |
|
–mode选项
–mode选项 | 说明 | 备注 |
---|
compile | 将一个源文件编译为Libtool目标文件 |
|
link | 生成一个库或者可执行文件 |
|
install | 安装一个库或可执行文件 |
|
execute | 运行可执行文件,并自动设置库路径 |
|
uninstall | 卸载库 |
|
clean | 从编译目录清楚生成的文件 |
|
finish | 完成Libtool库文件的安装 |
|
linux平台下动库的编译
编译目标文件
gcc -o jpg.o -c -fPIC jpg.c
生成动态库
gcc -o libjpg.so -shared jpg.o

libtool 的使用
libtool --help
original@192:/work/autotools/jpg$ 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)
--no-warn don't display warning messages
--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 message
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. 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: x86_64-redhat-linux-gnu
shell: /bin/sh
compiler: gcc
compiler flags: -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC
linker: /usr/bin/ld -m elf_x86_64 (gnu? yes)
libtool: (GNU libtool) 2.4.2
automake: automake (GNU automake) 1.13.4
autoconf: autoconf (GNU Autoconf) 2.69
Report 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/>.
original@192:/work/autotools/jpg$
示例
使用libtool编译库文件
libtool --tag=CC --mode=compile gcc -o jpg.lo -c jpg.c

libtool --tag=CC --mode=link gcc -o libjpg.la -c jpg.lo


使用libtool编译可执行文件
libtool --tag=CC --mode=compile gcc -I./ -c hello.c
libtool --tag=CC --mode=link gcc -o hello hello.lo ./libjpg.la
sudo libtool --mode=install install -c hello /usr/local/bin/
sudo libtool --mode=uninstall rm /usr/local/bin/hello
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-eAiEsXGn-1650621348983)(en-resource://database/21161:1)]
autoconf、automake 与 libtool 配合使用
编写Makefile.am
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-0b3STBPP-1650621348984)(en-resource://database/21163:1)]
生成配置脚本

以mp3
工程为例:

修改configure.ac

修改src/lcd/Makefile.am

修改src/usb/Makefile.am

修改src/Makefile.am

修改src/inc/Makefile.am

autoconf
autoheader
libtoolize --automake --copy --debug --force
aclocal
automake -a
./configure
编译结果:

推荐本站淘宝优惠价购买喜欢的宝贝:
本文链接:https://hqyman.cn/post/8252.html 非本站原创文章欢迎转载,原创文章需保留本站地址!
打赏

微信支付宝扫一扫,打赏作者吧~
休息一下~~