我们有一个VS 2019项目,其中包括我们添加到项目中的外部源库。例如,我们正在使用WTL(Windows模板库)。在编译期间,这些库会产生大量警告(尤其是对于没有默认值的成员)。
对于这些文件,我们希望完全禁用警告,或者至少指定某些目录应排除的警告,因为
我看到了有关一些标志的文章,您应该可以通过这些标志来禁用“外部”文件的警告,但是在项目设置中看不到任何选项。
有几种禁用警告的方法:
Project Properties->C/C++->General->Warning Level->select level
这是Warning Level
:
或者您可以选择禁用中的特定警告 Project Properties->C/C++->Advanced->Disable Specific Warnings
句法:
#pragma warning(
warning-specifier : warning-number-list
[; warning-specifier : warning-number-list ... ] )
#pragma warning( push [ , n ] )
#pragma warning( pop )
另外,您可以参考Microsoft有关如何:针对特定C / C ++警告启用和禁用代码分析的信息。
启用或禁用代码分析警告
2.1。创建一个头文件,列出所有代码分析警告及其初始状态,如以下代码所示:
// WarningState.h
#pragma warning ( default : 6001 )
#pragma warning ( disable : 6011 )
// more warnings here
// end of file
2.2。在应用程序头文件中包含WarningState.h。在这种情况下,MyApplication.h代表头文件。
// MyApplication.h file
#include "WarningState.h"
// ...
// end of file
2.3。在源代码文件中包含MyApplication.h文件。在这种情况下,MyApplication.cpp代表源文件。
// MyApplication.cpp file
#include "MyApplication.h"
2.4。要修改警告状态,请在.cpp文件中使用编译指示警告说明符,如以下代码所示:
// MyApplication.cpp file
#include "MyApplication.h"
#pragma warning ( disable: 6001 )
#pragma warning ( default : 6001 )
禁用包含的第三方文件的所有代码分析警告
将以下代码添加到头文件中。
#include <codeanalysis\warnings.h>
#pragma warning( push )
#pragma warning ( disable : ALL_CODE_ANALYSIS_WARNINGS )
#include <third-party include files here>
#pragma warning( pop )
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句