简体   繁体   English

VC ++ 2010:用/ Wall编译

[英]VC++ 2010: Compiling with /Wall

I'd like to compile my project with /Wall. 我想用/ Wall编译我的项目。

When I do this I get tons of warning from third-party code (boost libraries, other system header files). 当我这样做时,我从第三方代码(boost库,其他系统头文件)得到大量警告。 The only place where I include these third-party header files is in my precompiled header ( stdafx.h ). 我包含这些第三方头文件的唯一地方是在我的预编译头文件( stdafx.h )中。

I tried this (in stdafx.h ) 我试过这个(在stdafx.h

#pragma warning(push,3)
    // include all the third-party headers here
#pragma warning(pop)

to compile all third-party code with warning level 3. 编译警告级别为3的所有第三方代码。

However I still get hundreds of warnings from files like math.h , xmemory , vector , string_generator.hpp (boost.uuid), placeholders.hpp (boost.asio), ... 但是我仍然从math.hxmemoryvectorstring_generator.hpp (boost.uuid), placeholders.hpp (boost.asio)等文件中收到数百条警告。

How can I make sure to compile all third-party code with warning level 3 while compiling my own code with all warnings enabled? 如何在启用所有警告的情况下编译自己的代码时,如何确保编译警告级别为3的所有第三方代码?

3rd party code is modified less frequently, so it's a good idea to have all these includes in your StdAfx.h and then your above solution would suppress their warnings. 第三方代码的修改频率较低,因此最好将所有这些包含在您的StdAfx.h中,然后您的上述解决方案将禁止其警告。

Either that or create some other wrapper header files that use the above pragma around the actual includes to the libraries you use. 或者创建一些其他包装器头文件,使用上面的pragma围绕实际包含到您使用的库。

I can't think of a third way. 我想不出第三种方式。 I say shove them all in the stdafx ( and where they're actually included, too. remember that stdafx is an optimization - not a replacement for careful selective including within your source files) 我推说他们都在stdafx( 以及他们实际上是包括在内,也记得stdafx是一种优化-不仔细选择的替代品,包括你的源文件中)

/W4 is more realistic than /Wall. / W4比/ Wall更逼真。 I routinely use stl, tr1, and windows headers with /W4. 我经常使用带/ W4的stl,tr1和windows标头。 I don't know about boost. 我不知道提升。

The reason wrapping the headers with the #pragma isn't enough is that some of the warnings are generated when instantiating templates or expanding macros (or perhaps even with inlining). 使用#pragma包装标头的原因还不够,在实例化模板或扩展宏(或者甚至可能使用内联)时会生成一些警告。

Check all of the includes that your files pull in. It may be that one of them likely resets warnings to their default state. 检查文件所包含的所有内容。可能是其中一个可能会将警告重置为默认状态。 I've seen this with either MFC or ATL headers that come with VC++ - some warnings are disabled and then re-enabled with a "default" call specifier rather than using a push/pop pair. 我已经看到了VC ++附带的MFC或ATL标题 - 一些警告被禁用,然后使用“默认”调用说明符而不是使用推/弹对重新启用。

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

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