How to configure Visual Studio not to output warnings from libraries?

纵饮孤独 提交于 2019-12-24 11:37:51

问题


Is there any way to prevent Visual Studio from printing out warnings from included libraries?

\Wall gives me loads of warnings from STL and Qt headers, although I only want to see those originating from my own code (i.e. the code which is part of the current Visual Studio project).


回答1:


You can use pragma to set the warning levels for each file.

So before you include

#pragma warning( push )
#pragma warning( disable : 4705 )
#pragma warning( disable : 4706 )
#pragma warning( disable : 4707 )
// Some code

#include your files here

#pragma warning( pop ) 

More information here: http://msdn.microsoft.com/en-us/library/2c8f766e%28v=vs.80%29.aspx




回答2:


That's the only portable way (if using -isystem with other compilers):

#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: ...)
#endif
#include <Q...>
#ifdef _MSC_VER
#pragma warning(pop)
#endif

Hopefully they will implement isystem one of these days:

https://visualstudio.uservoice.com/forums/121579-visual-studio-2015/suggestions/14717934-add-a-cl-exe-option-for-system-headers-like-gcc-s




回答3:


You can use warning level 4, it will only include warnings for your code.



来源:https://stackoverflow.com/questions/15834304/how-to-configure-visual-studio-not-to-output-warnings-from-libraries

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!