禁用 gcc 对不兼容选项的警告
我很好奇是否有一个选项可以禁用 gcc 关于参数对正在编译的语言无效的警告。
例如:
cc1: warning: command line option "-Wno-deprecated" is valid for C++/Java/ObjC++ but not for C
我们的构建系统传递了我们在整个构建过程中全局决定的警告。 我们有 C/C++ 代码,当尝试查找实际警告时,警告会变得非常烦人。
有什么建议么?
I'm curious if there is an option to disable gcc warnings about a parameter not being valid for the language being compiled.
Ex:
cc1: warning: command line option "-Wno-deprecated" is valid for C++/Java/ObjC++ but not for C
Our build system passes the warnings we have decided on globally across a build.
We have both C/C++ code and the warnings get real annoying when trying to find actual warnings.
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
在 gcc 中启用特定警告 -Wxxxx 并使用 -Wno-xxxx 禁用它们。
来自 GCC 警告选项:
然而@Neil 关于区分不同语言的选项是正确的。 如果您使用 make,您可以将所有 C 选项放入 CFLAGS,将所有 C++ 选项放入 CCFLAGS。
To enable specific warnings in gcc -Wxxxx and to disable them with -Wno-xxxx.
From the GCC Warning Options:
However @Neil is right about separating options for different languages. If you use make you can e.g. put all C options into CFLAGS and all C++ options into CCFLAGS.
在我看来,如果有这样一个选项,就必须有一个进一步的选项来关闭有关该选项的警告,等等。 所以我怀疑没有。
无论如何,对于完全不同的语言的构建使用相同的选项似乎有点奇怪 - 我会将不同的选项定义为 makefile 宏并适当地用于不同的目标。
It seems to me that if there were such an option, there would have to be a further option to turn off warnings about that option, and so on infinitely. So I suspect there isn't.
Having the same options for builds of completely different languages seems a bit odd anyway - I would have different options defined as makefile macros and used appropriately for different targets.
如果设置 CFLAGS 变量,它只会影响 C 文件,如果设置 CXXFLAGS 变量,它只会影响 C++ 文件,因此您可以轻松分离逻辑。
If you set the CFLAGS variable it will only effect C files, if you set CXXFLAGS variable it will only effect C++ files, so you can easily separate the logic.
唉,gcc 无法打开或关闭单独的警告。 有些警告是特殊情况,并且可以设置警告级别,但无法关闭您不关心的警告。
我的意思是谁会关心文件末尾缺少空行? 我知道有一个补丁可以将其关闭,但是从源代码构建我的编译器有点太多了。
对于您的构建系统,您可能需要为不同的语言定义单独的警告集。 如果您需要使用其他编译器而不是 gcc 会发生什么?
Alas gcc doesn't have ability to turn individual warnings on or off. Some warnings are special cased, and warning levels can be set, but no way to turn off warnings you don't care about.
I mean who would ever care about missing empty line at the end of the file? I know there is a patch to turn it off, but building my complier from source is a bit too much.
For your build system you might want to define separate sets of warnings for different languages. What will happen if you need to use some other compiler, not gcc?
如果您可以选择将 C 文件编译为 C++,则
-x c++
。If compiling your C files as C++ is an option for you,
-x c++
.