其中,以添加CFLAG,如-std = gnu99,成自动工具项目 [英] Where to add a CFLAG, such as -std=gnu99, into an autotools project

查看:2029
本文介绍了其中,以添加CFLAG,如-std = gnu99,成自动工具项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的自动工具C ++项目(不是C ++)。

CFLAGS(通过检查)似乎是 -g -O2

我希望所有的生成make文件也有 -std = gnu99 追加到CFLAGS,因为我用的for(int i = 0; I< MAX;我++)和类似

我能明显破解Makefile文件,但这个被覆盖上 ./配置

哪里是正确的地方加入(或改变),这是由code要求(相对于该用户可能要更改这些CFLAGS)CFLAGS?

(注意:这是<部分重复href=\"http://stackoverflow.com/questions/11633763/where-to-add-a-cflag-such-as-std-gnu99-into-an-eclipse-cdt-autotools-project\">Where添加CFLAG,如-std = gnu99,成(Eclipse CDT的)自动工具项目因为我得到它我不想具体Eclipse的答案。)


@ DevSolar的回答还没有帮助。 A configure.ac 文件(如下图)生成配置脚本(下文)。

configure.ac:

  DNL处理此文件对于autoconf产生的配置脚本。CFLAGS =$ CFLAGS -std = gnu99
AC_ preREQ(2.59)
AC_INIT(tuntest,1.0)
AC_CANONICAL_SYSTEM
AM_INIT_AUTOMAKE()AC_PROG_CCAC_CONFIG_FILES(SRC的Makefile / Makefile中)
AC_OUTPUT

$ grep的CFLAGS配置

  CFLAGS
CFLAGS
要指定环境变量(例如,CC,CFLAGS ...),它们指定为
  CFLAGS C编译器的标志
ac_compile ='$ CC -c $ CFLAGS $ CPPFLAGS conftest $ ac_ext方式&gt;和5'
ac_link ='$ CC -o conftest $ ac_exeext $ CFLAGS $ CPPFLAGS $ LDFLAGS conftest $ ac_ext $ LIBS方式&gt;和5'
ac_compile ='$ CC -c $ CFLAGS $ CPPFLAGS conftest $ ac_ext方式&gt;和5'
ac_link ='$ CC -o conftest $ ac_exeext $ CFLAGS $ CPPFLAGS $ LDFLAGS conftest $ ac_ext $ LIBS方式&gt;和5'
ac_test_CFLAGS = $ {CFLAGS +集}
ac_save_CFLAGS = $ CFLAGS
   CFLAGS = - G
  CFLAGS =
     CFLAGS = - G
如果测试$ ac_test_CFLAGS=集;然后
  CFLAGS = $ ac_save_CFLAGS
    CFLAGS = - 摹-O2
    CFLAGS = - G
    CFLAGS = - O2
    CFLAGS =
ac_compile ='$ CC -c $ CFLAGS $ CPPFLAGS conftest $ ac_ext方式&gt;和5'
ac_link ='$ CC -o conftest $ ac_exeext $ CFLAGS $ CPPFLAGS $ LDFLAGS conftest $ ac_ext $ LIBS方式&gt;和5'


解决方案

的autoconf有此宏:

只要把:

  AC_PROG_CC_STDC

在你的 AC_PROG_CC ,一切都将是正确的。

特别是当你使用其他编译器不具有 -std = gnu99 但默认情况下在C99模式下运行(或者有不同的选项HPCC的 -AC99 泉记)。

我就不会使用 CFLAGS 的那种事。

从文档:

  - 宏:AC_PROG_CC_STDC
如果C编译器不能编译ISO标准C(目前C99)
尝试将选项添加到输出变量`CC',使其工作。如果
编译器不支持C99,回落到支持ANSI
C89(ISO C90)。调用此宏之后,您可以检查C编译器是否有
被设置成接受标准C;如果不是,shell变量
`ac_cv_prog_cc_stdc'设置为'无'。

I have a simple Autotools C project (not C++).

CFLAGs (by inspection) seem to be -g -O2.

I want all of the generated make files to also have -std=gnu99 appended to the CFLAGs, because I use for (int i = 0; i < MAX; i++) and similar.

I can obviously hack the Makefile, but this gets overwritten on ./configure.

Where is the correct place to add (or change) CFLAGs which are required by the code (as opposed to those CFLAGs which the user might want to change)?

(Note this is partial duplicate of Where to add a CFLAG, such as -std=gnu99, into an (Eclipse CDT) autotools project as I was getting Eclipse-specific answers which I didn't want.)


@DevSolar's answer has not helped yet. A configure.ac file (below) generates the configure script (also below).

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

$ grep CFLAGS configure

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'

解决方案

autoconf has a macro for this:

Just put:

AC_PROG_CC_STDC

after your AC_PROG_CC and everything will be right.

Especially when you use other compilers that do not have -std=gnu99 but operate in C99 mode by default (or have a different option hpcc's -AC99 springs to mind).

I would NOT use CFLAGS for that kind of thing.

From the docs:

-- 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'.

这篇关于其中,以添加CFLAG,如-std = gnu99,成自动工具项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆