且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何禁用没有命令行开关的gcc警告?

更新时间:2022-10-15 17:25:44

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

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