【问题标题】:Enforce strict C99 in Autoconf project在 Autoconf 项目中强制执行严格的 C99
【发布时间】:2012-05-15 00:23:56
【问题描述】:

我有一个用 C 编写的程序,它使用 Autoconf。它在configure.ac 中使用AC_PROG_CC_C99,与gcc 一起使用时会转换为-std=gnu99 编译器选项。该程序严格按照 C99 规范编写,不使用任何 GNU 扩展。

我们应该如何设置 Autoconf 以使编译器强制执行该操作?

【问题讨论】:

  • 您要查找的标志是-std=c99 -pedantic,需要以CFLAGS 结尾;不过,不知道如何最好地解决这个问题:(
  • 谢谢。我假设我可以手动添加它们,但如果可能的话,我更希望 Autoconf 做到这一点。不知道是否支持。

标签: c gcc c99 autotools autoconf


【解决方案1】:

我通常使用一个 m4 宏来检查给定的编译器是否接受某个 CFLAG。

将以下内容放入您的 aclocal.m4(我通常使用 m4/ax_check_cflags.m4 代替):

# AX_CHECK_CFLAGS(ADDITIONAL-CFLAGS, ACTION-IF-FOUND, ACTION-IF-NOT-FOUND)
#
# checks whether the $(CC) compiler accepts the ADDITIONAL-CFLAGS
# if so, they are added to the CXXFLAGS
AC_DEFUN([AX_CHECK_CFLAGS],
[
  AC_MSG_CHECKING([whether compiler accepts "$1"])
  cat > conftest.c++ << EOF
  int main(){
    return 0;
  }
  EOF
  if $CC $CPPFLAGS $CFLAGS -o conftest.o conftest.c++ [$1] > /dev/null 2>&1
  then
    AC_MSG_RESULT([yes])
    CFLAGS="${CFLAGS} [$1]"
    [$2]
  else
    AC_MSG_RESULT([no])
   [$3]
  fi
])dnl AX_CHECK_CFLAGS

然后从 configure.ac 中调用它

AX_CHECK_CFLAGS([-std=c99 -pedantic])

【讨论】:

    猜你喜欢
    • 2016-05-05
    • 2014-05-26
    • 1970-01-01
    • 1970-01-01
    • 2010-09-27
    • 2014-06-11
    • 2018-07-18
    • 2022-06-29
    • 2022-01-26
    相关资源
    最近更新 更多