禁用 gcc 对不兼容选项的警告

发布于 2024-07-24 09:49:12 字数 273 浏览 10 评论 0原文

我很好奇是否有一个选项可以禁用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

〃温暖了心ぐ 2024-07-31 09:49:12

在 gcc 中启用特定警告 -Wxxxx 并使用 -Wno-xxxx 禁用它们。

来自 GCC 警告选项

您可以使用以 -W' 开头的选项请求许多特定警告,例如 -Wimplicit 请求有关隐式声明的警告。 这些特定警告选项中的每一个都有一个以-Wno-'开头的否定形式来关闭警告; 例如,-Wno-隐式。 本手册仅列出了两种形式中的一种,以非默认形式为准。

然而@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:

You can request many specific warnings with options beginning -W', for example -Wimplicit to request warnings on implicit declarations. Each of these specific warning options also has a negative form beginning-Wno-' to turn off warnings; for example, -Wno-implicit. This manual lists only one of the two forms, whichever is not the default.

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.

赠我空喜 2024-07-31 09:49:12

在我看来,如果有这样一个选项,就必须有一个进一步的选项来关闭有关该选项的警告,等等。 所以我怀疑没有。

无论如何,对于完全不同的语言的构建使用相同的选项似乎有点奇怪 - 我会将不同的选项定义为 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.

哑剧 2024-07-31 09:49:12

如果设置 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.

荭秂 2024-07-31 09:49:12

唉,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?

疯到世界奔溃 2024-07-31 09:49:12

如果您可以选择将 C 文件编译为 C++,则-x c++

If compiling your C files as C++ is an option for you, -x c++.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文