Next: , Previous: , Up: Building Programs and Libraries   [Contents][Index]


7.4 Building a Shared Library

Building shared libraries is a relatively complex matter. For this reason, GNU Libtool (see The Libtool Manual in The Libtool Manual) was created to help build shared libraries in a platform-independent way.

Automake uses Libtool to build libraries declared with the ‘LTLIBRARIES’ primary. Each ‘_LTLIBRARIES’ variable is a list of shared libraries to build. For instance, to create a library named libgettext.a and its corresponding shared libraries, and install them in ‘libdir’, write:

lib_LTLIBRARIES = libgettext.la

Note that shared libraries must be installed, so ‘noinst_LTLIBRARIES’ and ‘check_LTLIBRARIES’ are not allowed.

For each library, the ‘library_LIBADD’ variable contains the names of extra libtool objects (‘.lo’ files) to add to the shared library. The ‘library_LDFLAGS’ variable contains any additional libtool flags, such as ‘-version-info’ or ‘-static’.

Where an ordinary library might include @LIBOBJS@, a libtool library must use @LTLIBOBJS@. This is required because the object files that libtool operates on do not necessarily end in ‘.o’. The libtool manual contains more details on this topic.

For libraries installed in some directory, automake will automatically supply the appropriate ‘-rpath’ option. However, for libraries determined at configure time (and thus mentioned in EXTRA_LTLIBRARIES), automake does not know the eventual installation directory; for such libraries you must add the ‘-rpath’ option to the appropriate ‘_LDFLAGS’ variable by hand.

See The Libtool Manual in The Libtool Manual, for more information.