我想在autotools项目中使用-Wall-Werror作为gcc的标志,但我不想将它们放在configure.ac中。
因此,我尝试使用./configure CFLAGS='-Wall -Werror',但从其中一个AC_SEARCH_LIBS宏调用中得到错误:

AC_SEARCH_LIBS([pow], [m], , AC_MSG_ERROR([Could not find standard math library.]))

在添加CFLAGS的情况下运行configure时产生的错误:
configure: error: Could not find standard math library.

我在这里做错什么了?在没有CFLAGS变量集的情况下,配置工作正常。

最佳答案

如您现在所知,将编译警告提升为错误会混淆./configure
您可以做的是在CFLAGS时间传递自定义make

$ ./configure
$ make CFLAGS='-O2 -g -Wall -Wextra -Werror'

另一个选项是William Pursell的方法:将选项添加到./configure以启用-Werror(如果支持):
(配置.ac)
AC_ARG_ENABLE([werror],
              [AS_HELP_STRING([--enable-werror], [Use -Werror @<:@no@:>@])],
              [:],
              [enable_werror=no])
AM_CONDITIONAL([ENABLE_WERROR], [test "$enable_werror" = yes])

(Makefile.am)
if ENABLE_WERROR
AM_CFLAGS += -Werror
endif

09-03 22:10