8.3.9.2 Error: ‘Libtool library used but 'LIBTOOL' is undefined’—libtoolize redux

This error message results from Automake seeing Libtool being used in Makefile.am, but the LIBTOOL variable is not defined. There are two common reasons for this. First, LT_INIT is missing from configure.ac; it can simply be added.

The second reason is more complicated: if you’ve installed Automake under a separate prefix, Automake cannot know where to find the LT_INIT macro. Automake looks in the aclocal.m4 file, which is generated by the aclocal command (see Auto-generating aclocal.m4: Invoking aclocal). But since the default search paths for aclocal are based on where it is installed (see Macro Search Path), if Automake is installed in one place (e.g., because it’s for a test release), and Libtool in another (e.g., for general system use), libtool.m4 won’t be found by aclocal and thus LT_INIT won’t be defined.

The best solution is to run libtoolize in the tree that is using the separately-installed Automake. That will copy libtool.m4 and the other Libtool M4 files and scripts into your package, including ltmain.sh (see previous section). If you have subpackages that use Libtool independently, you’ll need to run libtoolize in each of them. See Invoking libtoolize in The Libtool Manual.

The libtoolize output suggests using an m4 subdirectory:

libtoolize: Consider adding 'AC_CONFIG_MACRO_DIRS([m4])' to configure.ac,
libtoolize: and rerunning libtoolize and aclocal.
libtoolize: Consider adding '-I m4' to ACLOCAL_AMFLAGS in Makefile.am.

For purposes of Libtool and Automake, however, an m4 subdirectory is required, not just something to consider. Without having the Libtool M4 files in the local package, aclocal will (frustratingly) report the same ‘Libtool library used but ...’ error. (The name of the subdirectory for the M4 files can be anything, but ‘m4’ is by far the most common convention.)

Here is a concrete example. Suppose you’ve installed a test release of Automake (thank you) with --prefix=/tmp/amtest, and thus put /tmp/amtest/bin first in your PATH. You already have Libtool installed under /usr/local/gnu. Then, your Libtool-using package will fail to bootstrap, with the error:

Makefile.am:161: error: Libtool library used but 'LIBTOOL' is undefined
...

You can resolve this by ensuring your configure.ac includes these lines (after the AM_INIT_AUTOMAKE):

AC_CONFIG_MACRO_DIRS([m4])
AM_PROG_AR
LT_INIT

and then running:

libtoolize
autoreconf

To summarize, the libtoolize (from the system directory) copies libtool.m4 and the other Libtool support files into your package. The subsequent autoreconf then runs aclocal (under the test prefix) which can now find LT_INIT.

(For more discussion of this, see https://bugs.gnu.org/71847.