我有一个简单的Autotools C项目(不是C++).
CFLAG(通过检查)似乎是-g -O2
.
我希望所有生成的make文件也-std=gnu99
附加到CFLAGs,因为我使用for (int i = 0; i < MAX; i++)
和类似.
我显然可以破解Makefile,但这会被覆盖./configure
.
添加(或更改)代码所需的CFLAG的正确位置在哪里(与用户可能想要更改的CFLAG相对)?
(注意,这是将一个CFLAG(例如-std = gnu99)添加到(Eclipse CDT)autotools项目中的部分重复,因为我得到了我不想要的特定于Eclipse的答案.)
@ DevSolar的回答还没有帮助.甲configure.ac
文件(下面)生成configure
脚本(下文).
configure.ac:
dnl Process this file with autoconf to produce a configure script.
CFLAGS="$CFLAGS -std=gnu99"
AC_PREREQ(2.59)
AC_INIT(tuntest, 1.0)
AC_CANONICAL_SYSTEM
AM_INIT_AUTOMAKE()
AC_PROG_CC
AC_CONFIG_FILES(Makefile src/Makefile)
AC_OUTPUT
Run Code Online (Sandbox Code Playgroud)
$ grep CFLAGS配置
CFLAGS
CFLAGS
To assign environment variables (e.g., CC, CFLAGS...), specify them as
CFLAGS C compiler flags
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_test_CFLAGS=${CFLAGS+set}
ac_save_CFLAGS=$CFLAGS
CFLAGS="-g"
CFLAGS=""
CFLAGS="-g"
if test "$ac_test_CFLAGS" = set; then
CFLAGS=$ac_save_CFLAGS
CFLAGS="-g -O2"
CFLAGS="-g"
CFLAGS="-O2"
CFLAGS=
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
Run Code Online (Sandbox Code Playgroud)
hro*_*tyr 26
autoconf有一个宏:
刚刚放:
AC_PROG_CC_STDC
Run Code Online (Sandbox Code Playgroud)
在你AC_PROG_CC
和一切都将是正确的.
特别是当你使用其他没有-std=gnu99
但在默认情况下以C99模式运行的编译器时(或者有一个不同的选项hpcc的-AC99
泉水).
我将不使用CFLAGS
的那种事.
来自文档:
-- Macro: AC_PROG_CC_STDC If the C compiler cannot compile ISO Standard C (currently C99), try to add an option to output variable `CC' to make it work. If the compiler does not support C99, fall back to supporting ANSI C89 (ISO C90). After calling this macro you can check whether the C compiler has been set to accept Standard C; if not, the shell variable `ac_cv_prog_cc_stdc' is set to `no'.