简体   繁体   English

更改第三方库的警告级别

[英]Changing Warning Level for 3rd Party Libs

I generally like to compile against warning level 4 in Visual Studio and treat all warnings as errors. 我通常喜欢在Visual Studio中针对警告级别4进行编译,并将所有警告视为错误。 The problem is, Ogre3D is not compiled with warning level 3 (neither is FBX SDK or OIS, which I am also using), and that poses a problem because now I have a ton of warnings from Ogre3D libraries that are now treated as errors. 问题是,Ogre3D没有编译警告级别3(FBX SDK或OIS,我也在使用),这也是一个问题,因为现在我收到了来自Ogre3D库的大量警告,现在被视为错误。 So far I have been compiling at level 3, but that makes me very uneasy. 到目前为止,我一直在第3级编译,但这让我非常不安。 Is there any way to disable warnings for specific 3rd party libraries over which I have no control? 有没有办法禁用我无法控制的特定第三方库的警告?

You don't say exactly how you are compiling, but here are some options: 你没有确切地说你是如何编译的,但这里有一些选择:

1 - Inside Visual Studio, you can set the warning level for individual source files via the Properties for each source file 1 - 在Visual Studio中,您可以通过每个源文件的“属性”设置各个源文件的警告级别

2 - You can also change the the warning level dynamically within a file using 2 - 您还可以使用在文件中动态更改警告级别

#pragma warning(push, 3)
// Some code, perhaps #includes
#pragma warning(pop)

which sets the warning level to 3 between the two pragmas. 它将两个pragma之间的警告级别设置为3。

It may be that if you disable the most well-known MSVC sillywarnings, the problem will at least become managable. 可能是因为如果你禁用最知名的MSVC愚蠢警告,问题至少会成为可管理的问题。

My sillywarnings suppression header is available at my blog ; 我的博客上提供了我的愚蠢警告抑制标题; it's enough to compile code using <windows.h> at warning level 4 with MSVC, with no warnings. 使用MSVC在警告级别4使用<windows.h>编译代码就足够了,没有任何警告。

Other than that, you can go to the extreme measure of employing a "compiler firewall", which means putting all direct usage of the 3rd party library within an implementation file or set of such files. 除此之外,您可以采用“编译器防火墙”的极端措施,这意味着将第三方库的所有直接使用都放在实现文件或一组此类文件中。 Then you can compile those files at low warning level. 然后,您可以在低警告级别编译这些文件。 But I don't think it's worth it. 但我不认为这是值得的。

Cheers & hth., 干杯&hth。,

You can wrap the 3rd party .h files into your own file and in there disable locally the offending warnings as you might not want to disable all warnings but only specific ones. 您可以将第三方.h文件包装到您自己的文件中,然后在本地禁用有问题的警告,因为您可能不想禁用所有警告但仅禁用特定警告。

// include_file_wrapper.h

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wuninitialized"

#include "file.h"

#pragma GCC diagnostic pop

For gcc here is how this can be done 对于gcc来说,这是如何做到的

http://gcc.gnu.org/onlinedocs/gcc/Pragmas.html http://gcc.gnu.org/onlinedocs/gcc/Pragmas.html

http://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html#Diagnostic-Pragmas http://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html#Diagnostic-Pragmas

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM