【问题标题】:Static assertion failed with "Windows headers require the default packing option..."静态断言因“Windows 标头需要默认打包选项...”而失败
【发布时间】:2019-06-12 21:35:34
【问题描述】:

当我尝试在 Visual Studio 中编译我的 C++ 项目时,我不断收到以下 2 个错误:

E1574: Static assertion failed with "Windows headers require the default 
packing option. Changing this can lead to memory corruption. This diagnostic 
can be disabled by building with WINDOWS_IGNORE_PACKING_MISMATCH defined."

C2338: Windows headers require the default packing option. Changing this can 
lead to memory corruption. This diagnostic can be disabled by building with 
WINDOWS_IGNORE_PACKING_MISMATCH defined.

我认为问题出在我的 Visual Studio 设置中,因为项目在我的另一台 PC 上编译良好,而我刚刚在这台 PC 上安装了 Visual Studio。

通过一些搜索,问题似乎源于 Windows 包不匹配,但是在安装 Visual Studio 时,我尝试安装我看到的所有 C++ 和 Windows 10 模块。

另外,为了使用ShellExecute(),我只包括windows.h,所以如果有更好的方法来使用ShellExecute(),我愿意接受。谢谢!

【问题讨论】:

  • 不要使用/Zp(结构打包)编译器选项。
  • @1201ProgramAlarm 谢谢这似乎有效!这种方法有什么缺点吗?
  • 真正的问题是你为什么要在第一位添加/Zp
  • @RichardCritten 超级具体,Adobe After Effects Plugin SDK,Struct Member Alignment 设置为4 Byte (/Zp4)
  • @JustinTaylor -- 那么无论谁把那个包裹放在一起,都可悲的是没有注意。有一些方法可以在源代码本身中设置自定义结构的打包(例如pragma pack),而不是通过通用编译器开关来搞砸其他结构。

标签: c++ windows visual-studio header-files


【解决方案1】:

正如上面提到的 1201ProgramAlarm,解决方案是禁用 /Zp(结构打包)编译器选项。

【讨论】:

  • 我可以在 MSVC 的哪个位置禁用此功能?我四处搜寻,但没有发现任何有用的东西:/
  • @LilaQ 转到项目设置 > C/C++ > 代码生成 > 结构成员对齐(更改为默认值)
  • 对我不起作用。如果没有编译器选项 /Zp,问题仍然存在。我正在使用平台工具集 v142。有趣的是,我对 v141 没有任何问题。
猜你喜欢
  • 2015-02-15
  • 1970-01-01
  • 1970-01-01
  • 2022-08-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多