如何GCC的行为,如果通过冲突的编译器标志? [英] How does GCC behave if passed conflicting compiler flags?

查看:165
本文介绍了如何GCC的行为,如果通过冲突的编译器标志?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道,如果你执行GCC这样:

  GCC -O3 -O2 foo.c的

GCC将使用通过了最后的优化标志(在这种情况下, O2 )。然而,这是适用于所有的标志吗?例如,如果我执行GCC像这样:

  gcc的-mno-SSE -msse bar.c

它将支持SSE,因为这是最后的标志过去了,还是会这样的结果不确定的行为?我最初的实验似乎表明它将支持SSE,但我不知道这是对所有情况属实。


解决方案

通常后来就行了覆盖那些通过previously,正如你在第一个例子中提到的选项。我没有亲自遇到任何不同的行为 -m -f 标记,但我不知道的文档中特定的参考。

请注意,某些选项不规矩是这样的:

  $ GCC example.c -DABC -DABC = 12
<命令行计算值:警告:ABC重新定义
<命令行计算值:警告:这是previous定义的位置

所以就需要一个 -UABC 之间有关闭该警告的。

顺便说一句,是解决这个问题特别好 - 如果它忽略了一个命令行选项,它可以帮你会产生警告

I know that if you execute GCC as such:

gcc -O3 -O2 foo.c

GCC will use the last optimization flag passed (in this case O2). However, is this true for all flags? For example, if I execute GCC like so:

gcc -mno-sse -msse bar.c

Will it support SSE since that was the last flag passed, or would this result in undefined behavior? My initial experimentation seems to indicate that it will support SSE, but I'm not sure if this is true for all cases.

解决方案

Normally later options on the line override ones passed previously, as you mention in your first example. I haven't personally come across any different behaviour for -m or -f flags, but I don't know of a specific reference in the documentation.

Note that some options don't behave this way:

$ gcc example.c -DABC -DABC=12
<command-line>: warning: "ABC" redefined
<command-line>: warning: this is the location of the previous definition

So there would need to be a -UABC in between there to shut that warning up.

As an aside, clang is particularly good at solving this problem - it will produce a warning if it ignores a command line option, which can help you out.

这篇关于如何GCC的行为,如果通过冲突的编译器标志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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