如何禁用没有命令行开关的gcc警告? [英] How do I disable a gcc warning which has no command line switch?

查看:90
本文介绍了如何禁用没有命令行开关的gcc警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到以下警告:

 警告:"X"已初始化并声明为"extern" 

看起来没什么大不了,我可以将其禁用.在我的情况下,更改代码并不是一个好主意,因为我无法控制代码,只需要编译即可.所以我想禁用警告.

如果它旁边有一个 -WSomeDefect 键,则可以使用 -Wno-SomeDefect 命令行开关,但此警告似乎没有明显的开关

如何禁用此类警告?

解决方案

有关所提出问题的直接答案:

从GCC的源代码可以看出,没有(半)特定的开关可以禁用此警告.似乎只能通过禁用所有警告( -w )或通过 -isystem 将有问题的代码作为系统头文件来禁用,这两种情况在抑制状态中都是非特定的警告.

此处上有一个有关GCC的相关打开的错误报告.此处的开放式meta-bug,用于类似情况的警告.

如果您不想使用两种非特定的抑制机制,则可能必须在GCC中打上额外的标志,或者等待错误解决后才能禁用此特定警告./p>

I get the following warning:

warning: 'X' is initialized and declared 'extern'

and it looks like it's no big deal and I could disable it. Changing the code is not really a good idea in my case because I have no control over the code, I just need to compile it. So I want to disable the warning.

If it had a -WSomeDefect key next to it then I could use a -Wno-SomeDefect command line switch but it looks like there's no distinct switch for this warning.

How do I disable such warning?

解决方案

For a direct answer to the posed question:

As can be seen from GCC's source code, there is no (semi-)specific switch to disable this warning. It seems to only be disabled by disabling all warning (-w) or including the offending code as system header via -isystem, both of which are non-specific in the suppressed warnings.

There is a related open bug report on GCC here and an open meta-bug for similar cases of warnings without switches here.

If you don't want to use the two non-specific suppression mechanisms, then you probably will have to patch in an additional flag to GCC or wait for the bugs to be worked on in order to disable this specific warning.

这篇关于如何禁用没有命令行开关的gcc警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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