问题描述
Almost each system has its own format of shared library
libhello.dll
libhello.sl
libhello.dylib
…
Building will require different flags
-KPIC, -G
-bM:SRE
…
Linking against the library may also require specific flags.
There is no way for a developer to keep track of all these details.
Not all systems support shared libraries.
解决方案
Libtool 将解决上述问题。
原理简述
A new library format that abstracts all the others
A wrapper script for the compiler and linker
In a Makefile.am, you simply create and link against *.la files.
These operations are translated appropriately.
特性特征
简化共享库的使用,不再需要处理复杂的多平台移植性问题。
应用
使用方法
Libtool will require some local Autoconf macros for all the checks it has to perform. Use an m4/ subdirectory as explained earlier.
Call LT_INIT in configure.ac. Use LTLIBRARIES to declare libtool archives in Makefile.am
Use _LDADD to link against local libtool archives.
Makefile.am
lib_LTLIBRARIES = libfoo.la libfoo_la_SOURCES = foo.c foo.h etc.c bin_PROGRAMS = runme runme_SOURCES = main.c runme_LDADD = libfoo.la # 通过 _LDADD 来使用库