How to fix autoconf error: possibly undefined macro: AM_INIT_AUTOMAKE

Problem

When running autoconf, you see an error message such as

configure.ac:15: error: possibly undefined macro: AM_INIT_AUTOMAKE
      If this token and others are legitimate, please use m4_pattern_allow.
      See the Autoconf documentation.
configure.ac:29: error: possibly undefined macro: AC_PROG_LIBTOOL
configure.ac:36: error: possibly undefined macro: AC_MSG_ERROR
configure.ac:38: error: possibly undefined macro: AM_CONDITIONAL
configure.ac:55: error: possibly undefined macro: AC_CHECK_PTHREAD_SETNAME_NP

Solution

Before running autoconf, you need to run aclocal to generate the aclocal.m4 file.

aclocal

After that, you can run autoconf again and the error should be gone.