【问题标题】:Visual Studio 2013 doesn't ignore disabled warningsVisual Studio 2013 不会忽略禁用的警告
【发布时间】:2017-03-07 18:27:27
【问题描述】:

大家早上好。所以我试图在我们的 c++ 项目中禁用警告 4996。它似乎包含在命令行中,如下所示,但在编译时,仍然弹出 C4966 警告。我尝试将警告级别更改为 3,或使用 /w44996,但都没有奏效。有谁知道为什么会这样?

/Yu"stdafx.h" /GS- /W4 /wd"4100" /wd"4121" /wd"4201" /wd"4214" /wd"4244" /wd"4996" /Zc:wchar_t /I"C:\Program Files (x86)\MSBuild\..\Common Files\Microsoft Shared\MSEnv" /I"C:\Program Files (x86)\MSBuild\..\Common Files\Designer" /I"D:\Workspaces\MST_Sustaining_Second\Inc" /I"D:\Workspaces\MST_Sustaining_Second\Develop\Shared\Include" /Zi /Gm /Od /Fd"D:\Workspaces\MST_Sustaining_Second\Develop\IDE\GrACE\Debug\vc120.pdb" /fp:precise /D "_USRDLL" /D "ACE_DLL" /D "IQEDITOR_ENABLED" /D "_WINDOWS" /D "_DEBUG" /D "NTDDI_VERSION=NTDDI_WIN7" /D "_WIN32_WINNT=0x0601" /D "WINVER=0x0601" /D "_AFXDLL" /D "WIN32" /D "_SECURE_SCL=0" /D "_WINDLL" /D "_MBCS" /errorReport:prompt /GF- /WX- /Zc:forScope /RTC1 /Gd /Oi /MDd /Fa"D:\Workspaces\MST_Sustaining_Second\Develop\IDE\GrACE\Debug\" /EHs /nologo /Fo"D:\Workspaces\MST_Sustaining_Second\Develop\IDE\GrACE\Debug\" /Fp"D:\Workspaces\MST_Sustaining_Second\Develop\IDE\GrACE\Debug\ace.pch" 

编辑:描述中的错字。我的意思是警告 4996,而不是 4966。4996 在命令行中为 /wd"4996"

警告:

warning C4996: 'MBCS_Support_Deprecated_In_MFC': MBCS support in MFC is deprecated and may be removed in a future version of MFC.

【问题讨论】:

    标签: c++ compiler-construction visual-studio-2013 warnings


    【解决方案1】:

    看起来#pragma warning(disable: 4996) 不会禁用 MBCS 弃用警告,因为 #pragma warning(1: 4996) 在 afx.h 中 _declspec(deprecated) 行之前

    出于不明原因,您必须改用#define NO_WARN_MBCS_MFC_DEPRECATION 来禁用此功能。

    参见 afx.h 第 28-33 行

    #ifndef NO_WARN_MBCS_MFC_DEPRECATION
    #ifdef _MBCS
    // Warn about MBCS support being deprecated: see http://go.microsoft.com/fwlink/p/?LinkId=279048 for more information.
    #pragma warning(push)
    #pragma warning(1 : 4996)
    inline __declspec(deprecated("MBCS support in MFC is deprecated and may be removed in a future version of MFC.")) void MBCS_Support_Deprecated_In_MFC() { }
    

    【讨论】:

    【解决方案2】:

    为了Pat Brenner(Visual C++ Libraries Development Team)在他的blog中提到,

    我们将弃用 MFC for Visual Studio 2013 中的 MBCS 支持。这 使 MFC 与 Windows SDK 本身更紧密地保持一致,因为 许多最新的控件和消息仅使用 Unicode

    可以通过添加 NO_WARN_MBCS_MFC_DEPRECATION 预处理器定义到您的项目 构建定义。

    然后执行此操作。

    转到项目属性-> C\C++ ->预处理器->预处理器定义并添加NO_WARN_MBCS_MFC_DEPRECATION

    【讨论】:

      【解决方案3】:

      我遇到了类似的问题,但它来自 io.hstring.h 的某些功能,例如:

      source.cxx(713) : warning C4996: 'stricmp': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _stricmp. See online help for details. C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\string.h(215) : see declaration of 'stricmp'

      source.cxx(2416) : warning C4996: 'strdup': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _strdup. See online help for details. C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\string.h(207) : see declaration of 'strdup'

      source.cxx(2249) : warning C4996: 'isatty': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _isatty. See online help for det ails.

      由于需要在其他平台上运行完全相同的代码,我不得不找到一个解决方案,而无需大量修改代码,因为这发生在整个项目中的大量文件中。

      解决方案是添加此编译器标志_CRT_NONSTDC_NO_DEPRECATE。这可以通过以下两种方式之一完成:

      1. 如果您直接使用cl 命令,则传递-D_CRT_NONSTDC_NO_DEPRECATE
      2. 或来自Visual Studio GUI,如果您将其用于构建过程。在项目属性>C\C++>预处理器>预处理器定义中添加_CRT_NONSTDC_NO_DEPRECATE

      【讨论】:

      • 对于 VS 2017,它们是错误而不是警告。这是正确的答案。
      猜你喜欢
      • 1970-01-01
      • 2014-06-03
      • 1970-01-01
      • 2017-07-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-12
      • 2018-09-15
      相关资源
      最近更新 更多