autoreconf -fi error: possibly undefined macro: AC_DEFINE If this token and others are legitimate, please use m4_pattern_allow

autoreconf -fi error: possibly undefined macro: AC_DEFINE If this token and others are legitimate, please use m4_pattern_allow

我的 autoconf 设置相当新:

m4 (GNU M4) 1.4.17 and came with ubuntu
autoconf (GNU Autoconf) 2.69

我的configure.ac相当简单:

 30 ACX_PTHREAD([ 
 31   AC_DEFINE([HAVE_PTHREAD], [1], [Define if you have POSIX threads libraries and headers])
 32   gtest_LIBS="$PTHREAD_LIBS $LIBS"
 33   gtest_CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
 34   gtest_CXXFLAGS="$CXXFLAGS $PTHREAD_CXXFLAGS"
 35   gtest_CC="$PTHREAD_CC"
 36   gtest_CXX="$PTHREAD_CXX"])

运行 autconf 给我错误:

autoreconf -fi
libtoolize: putting auxiliary files in '.'.
libtoolize: copying file './ltmain.sh'
libtoolize: putting macros in AC_CONFIG_MACRO_DIRS, 'm4'.
libtoolize: copying file 'm4/libtool.m4'
libtoolize: copying file 'm4/ltoptions.m4'
libtoolize: copying file 'm4/ltsugar.m4'
libtoolize: copying file 'm4/ltversion.m4'
libtoolize: copying file 'm4/lt~obsolete.m4'
configure.ac:31: error: possibly undefined macro: AC_DEFINE
      If this token and others are legitimate, please use m4_pattern_allow.
      See the Autoconf documentation.

我认为我的 ACX_PTHREAD 宏给我带来了麻烦。我查看了这个宏的定义,没有发现任何奇怪的地方。有建议说这是其他情况下缺少pkg.m4造成的。我确认我的系统上安装了最新版本的 pkg-config。 pkg.m4 存在于我的系统中:/usr/share/aclocal。我一直在研究这个问题的解决方案,但一无所获。

原来我的问题是因为缺少 axc_pthread.m4 文件。我是这样发现的:

autoreconf -fi 给出了错误信息。如果我 运行 autoreconf -i 那么程序将 运行 静静地没有任何错误消息。 运行 ./configure 将在将 ACX_PTHREAD(...) 逐字复制到配置文件的行中揭示问题。这表明 ACX_PTHREAD 宏未在我的系统中定义。

下载 link 位于:http://ac-archive.sourceforge.net/ac-archive/acx_pthread.html。经过一些研究,似乎有很多来源提供了这个宏定义。不确定哪个更好。但我渴望解决这个问题。将此文件复制到我项目的 m4 目录后,我的问题就解决了。希望这可以帮助其他人。 autoconf 的问题是通常问题会显示错误的症状。