Autoconf - 不支持 POSIX 线程。配置可能使用错误的代码来验证支持。如何解决?

Autoconf - No POSIX thread support. Configure possibly using wrong code to verify support. How to fix it?

我正在使用 ./configure 配置其中一个项目。我从中得到以下错误。

checking for the pthreads library -lpthreads... no
checking whether pthreads work without any flags... no
checking whether pthreads work with -Kthread... no
checking whether pthreads work with -kthread... no
checking for the pthreads library -llthread... no
checking whether pthreads work with -pthread... no
checking whether pthreads work with -pthreads... no
checking whether pthreads work with -mthreads... no
checking for the pthreads library -lpthread... no
checking whether pthreads work with --thread-safe... no
checking whether pthreads work with -mt... no
checking for pthread-config... no
configure: error: POSIX threads support is required

当我检查配置文件时,我看到它使用以下代码来检查 pthread 支持:

#include <pthread.h>
int main ()
{
pthread_t th; pthread_join(th, 0);
                     pthread_attr_init(0); pthread_cleanup_push(0, 0);
                     pthread_create(0,0,0,0); pthread_cleanup_pop(0);
  ;
  return 0;
}

当我单独编译它时,它确实编译了。但有来自 pthread_create 的警告。

test_pthread.c:5:22: warning: null argument where non-null required (argument 1) [-Wnonnull]
                      pthread_attr_init(0); pthread_cleanup_push(0, 0);
                      ^
test_pthread.c:6:22: warning: null argument where non-null required (argument 1) [-Wnonnull]
                      pthread_create(0,0,0,0); pthread_cleanup_pop(0);
                      ^
test_pthread.c:6:22: warning: null argument where non-null required (argument 3) [-Wnonnull]

这是配置检查编译器对 -pthread 支持的方式的错误吗?我该如何解决这个问题?

我在 运行 ./configure 之前使用 autoreconf -i。什么是解决此问题的干净方法?

------------ 编辑:添加更多信息----------

我在 configure.ac 文件中使用以下行来检查 pthread。我刚从网上的配置中得到它。

# Check for POSIX thread support

    ACX_PTHREAD([
                     LIBS="$LIBS $PTHREAD_LIBS"
                     CFLAGS="$CFLAGS $PTHREAD_CFLAGS -g -Wall"
                     CC="$PTHREAD_CC"
                     AC_SUBST([LIBS])
                     AC_SUBST([CFLAGS])
                     AC_SUBST([CC])
                 ],
                 [AC_MSG_ERROR([POSIX threads support is required])])

从评论中可以看出,您在 autoconf 脚本的早期 CFLAGS 中设置了 -Werror

不要那样做。如果您想要 -Werror,请将其添加到 CFLAGS,就在脚本的 结尾 处,在调用编译器的所有测试都已 运行 之后。大多数 autoconf 测试不是为 -Werror.

编写的