「GNU-BUILD-SYSTEM」- Libtool

问题描述

Almost each system has its own format of shared library

libhello.so

libhello.dll

libhello.sl

libhello.dylib

Building will require different flags

-fPIC, -shared

-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.

Quiz: match each of the above example with its OS.

Not all systems support shared libraries.

解决方案

Libtool 将解决上述问题。

原理简述

A new library format that abstracts all the others

libhello.la (libtool archive)

A wrapper script for the compiler and linker

translates operations involving libhello.la into the correct operation for the current system using the real library

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 来使用库