Next: , Previous: Makefile rules, Up: Integrating libtool

5.3 Using Automake with libtool

Libtool library support is implemented under the ‘LTLIBRARIES’ primary.

Here are some samples from the Automake in the libtool distribution's demo subdirectory.

First, to link a program against a libtool library, just use the ‘program_LDADD1 variable:

     bin_PROGRAMS = hell hell_static
     # Build hell from main.c and
     hell_SOURCES = main.c
     hell_LDADD =
     # Create a statically linked version of hell.
     hell_static_SOURCES = main.c
     hell_static_LDADD =
     hell_static_LDFLAGS = -static

You may use the ‘program_LDFLAGS’ variable to stuff in any flags you want to pass to libtool while linking program (such as -static to avoid linking uninstalled shared libtool libraries).

Building a libtool library is almost as trivial... note the use of ‘libhello_la_LDFLAGS’ to pass the -version-info (see Versioning) option to libtool:

     # Build a libtool library, for installation in libdir.
     lib_LTLIBRARIES =
     libhello_la_SOURCES = hello.c foo.c
     libhello_la_LDFLAGS = -version-info 3:12:1

The -rpath option is passed automatically by Automake (except for libraries listed as noinst_LTLIBRARIES), so you should not specify it.

See Building a Shared Library, for more information.


[1] Since GNU Automake 1.5, the flags -dlopen or -dlpreopen (see Link mode) can be employed with the ‘program_LDADD’ variable. Unfortunately, older releases didn't accept these flags, so if you are stuck with an ancient Automake, we recommend quoting the flag itself, and setting ‘program_DEPENDENCIES’ too:

     program_LDADD = "-dlopen"
     program_DEPENDENCIES =