Windows headers require the default packing option

The Powder Toy

Error C2338 when compiling clean source.

I get an error when compiling a clean source from a premade VS project for TPT++ after following all of your instructions on the wiki page:

C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winnt.h(2482,40): error 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.

It terminates the build process. Anything I can do to stop it?

(I originally posted this in the development section, before I realised I should have posted it here.)

While I was compiling, I came across another error:

C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\xtgmath.h(22,47): warning C4244: ‘=’: conversion from ‘double’ to ‘int’, possible loss of data (compiling source file src\simulation\elements\SPRK.cpp)

SOLUTION:


Fix error C2338: setting /Zp to default doesn’t work — add WINDOWS_IGNORE_PACKING_MISMATCH to C++ > Preprocessor > Preprocessor definitions and it should bypass that.

Fix error C4244: this seemed to show up even if ‘treat warnings as errors’ was set to ‘No’. I found it worked if I set ‘warning level’ to ‘None’.

There’s a few things you can try:

Disable the option «Treat Warnings As Errors», as mentioned on the wiki page

Define WINDOWS_IGNORE_PACKING_MISMATCH under C++ > Preprocessor > Preprocessor definitions
(the error message seems to say it will work)

I also googled it, and it said turning off /Zp fixes it. I don’t remember this setting being set, I’ve actually never heard of it before. But if you can find it and turn it off, it might fix it. Google says this option is located at C/C++ > Code Generation > Struct Member Alignment

OK, thanks a lot! I have already disabled the ‘treat warnings as errors’ option, but I’ll try to find /Zp and see if that fixes it. If it doesn’t, I’ll define the WINDOWS_IGNORE_PACKING_MISMATCH thing.

EDIT:

Right, so setting /Zp to 16 bytes (if you have that option) got past that problem, now I have a new one:

C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\xtgmath.h(22,47): warning C4244: ‘=’: conversion from ‘double’ to ‘int’, possible loss of data (compiling source file src\simulation\elements\SPRK.cpp)

It appeared for SOAP (conversion from ‘double’ to ‘float’), and Gravity (‘double’ to ‘float’) as well.

Читайте также:  Если у меня много хост процессов для задач windows

@biran4454 (View Post)
That error is definitely caused by the option «Treat Warnings As Errors» being on, I’ve seen it before. It’s a visual studio bug. The error is in xtgmath.h, which is a standard include file and isn’t supposed to error.

So . double check that the option is off.

‘treat warnings as errors’ doesn’t fix it (I’ve tried all the options) and ‘turn off all warnings’ on ‘warning level’ (/W) doesn’t either. Also, when I have /Zp set to 16, which previously fixed the ‘default packing option’ it still brings up that error.

I have pasted 3 builds with different property combinations at https://bpaste.net/show/G7PW4.

@biran4454 (View Post)
Don’t set strict member alignment to 16, it should be default.

I see that all 3 of your builds still say this, and this is the actual error:
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winnt.h(2482,40): error 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. (compiling source file src\PowderToySDL.cpp)

If setting struct packing to default doesn’t fix it, try defining WINDOWS_IGNORE_PACKING_MISMATCH.

Transport Tycoon Forums

The place to talk about Transport Tycoon

  • Unanswered topics
  • Active topics
  • Search
  • Members
  • The team

Compiling error Win7, VS19 [1. time attempt]

Compiling error Win7, VS19 [1. time attempt]

Post by TheNewGuy » 01 Aug 2019 12:20

I normally do not work with Visual Studio (19) nor C/C++ for a while. Anyways, I wanted to compile (duh) ottd. I followed the howto (https://github.com/OpenTTD/OpenTTD/blob . ws_MSVC.md) resolved dependencies etc.etc..

Following error occurs which let the build fail: C2338

1. Does anyone experienced this as well and knows where it comes from?
2. Can anyone tell me how to resolve that? (I do not even know how I define the WINDOWS_IGNORE_PACKING_MISMATCH?!)

Any help would be great!

Thanks a lot for your work!!

Re: Compiling error Win7, VS19 [1. time attempt]

Post by jfs » 01 Aug 2019 15:08

Re: Compiling error Win7, VS19 [1. time attempt]

Post by TheNewGuy » 01 Aug 2019 17:03

Ouh hi. Nice. Thanks for the response.
Let’s dig into it.

A couple more details if that is a very uncommon error.
I open: openttd_vs142.sln

Then I go: Build -> Build Solution (not build openttd? right? Either way, the result is identical)

And I spare you the whole output as it literally(!) is:

80 times over and over again. Files: date.cpp, console.cpp, console_cmds.cpp, .

Regarding the second link, when I head to Project -> Properties -> C/C++ -> Command Line in «Additional Options» is: «/J /Zc:throwingNew /std:c++latest «.
However, removing ‘/Zc:throwingNew’ didn’t change any of the observed behavior. As I never use an IDE I am really digging in the dark and was hoping that someone has a direct solution to it.

How do you build this? #10

Comments

notflip commented Jun 3, 2020

No description provided.

The text was updated successfully, but these errors were encountered:

RudolfKurka commented Jun 3, 2020 •

I managed to build tibdawn dll with latest visual studio 2019 and tooling, only minimal changes, see my fork:

ps: you need windows SDK, MFC and VC headers installed (available as a component inside VS installer)

Читайте также:  Отключить ненужные службы windows 10 про

Hydra9268 commented Jun 4, 2020 •

1>Resource\TiberianDawn.rc(10): fatal error RC1015: cannot open include file ‘afxres.h’.

Hydra9268 commented Jun 4, 2020 •

error 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. (compiling source file win32lib\#######.CPP)

RudolfKurka commented Jun 4, 2020

I fixed those packing mismatch errors the same way but I was wondering if it’s a good idea. why was it set for 1-byte boundary? Is this intentional or just some leftover from 1995? Theres asm code in the dll, could some manual offseting rely on this setting? Thing is (judging on quick google) if you flip that switch to default it means 8-byte alignment (x86 default) which sounds potentially code breaking.

Hydra9268 commented Jun 4, 2020 •

The problem is two-fold. First, setting custom structs in the source code is better served with things like pragma pack instead of a universal compile switch that’ll screw up other structs. Second, the recent versions of Visual Studio (specifically 2019) appear to be more strict with how solutions handle struct packaging. At least, that’s my understanding based on the evidence. Feel free to correct me if I’m wrong.

igofreely commented Jun 5, 2020

Please give a compiler and sdk edition correctly for successful complie,thanks.

alexlk42 commented Jun 6, 2020

When building the source code I believe you should maintain the original data structure alignment/packing. I set up a repo that has this source configured for Visual Studio 2019. This repo preserves original data structure alignment/packing: https://github.com/alexlk42/CnC_Remastered_Collection. I tested the RedAlert.dll and it worked without crashing the game.

RudolfKurka commented Jun 6, 2020

You are right, the dll’s did not work and crashed upon loading. I changed my fork back to using 1-byte alignment and used your solution to suppress those packing errors and it’s all good now. Tried the tib dawn dll as well and both seem working fine, nice 🙂

alexlk42 commented Jun 6, 2020

That’s great! Glad the TD dll works as I hadn’t tested that one yet.

Hydra9268 commented Jun 7, 2020

Thanks, alex. That’s was cool of you to share your fix. 🙂

danger89 commented Jun 7, 2020

Linux build would be nice as well.

Hydra9268 commented Jun 7, 2020

You can likely run the remaster through Wine.

danger89 commented Jun 7, 2020

Yeah, properly. But now we have the source code! Yea!

Hydra9268 commented Jun 7, 2020

You can’t perform that action at this time.

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.

windows_ignore_packing_mismatch #869

Comments

Necktwi commented Aug 22, 2019

while building RDPWrap.vcxproj with visual studio I get the following error

Can I just add -DWINDOWS_IGNORE_PACKING_MISMATCH CXXFLAG without any runtime issues?

Below is my Visual Studio details:

Microsoft Visual Studio Community 2019
Version 16.2.1
VisualStudio.16.Release/16.2.1+29201.188
Microsoft .NET Framework
Version 4.8.03752

Installed Version: Community

Читайте также:  Softether vpn client linux gui

Visual C++ 2019 00435-60000-00000-AA711
Microsoft Visual C++ 2019

Application Insights Tools for Visual Studio Package 9.1.00611.1
Application Insights Tools for Visual Studio

ASP.NET and Web Tools 2019 16.2.290.48383
ASP.NET and Web Tools 2019

Azure App Service Tools v3.0.0 16.2.290.48383
Azure App Service Tools v3.0.0

C# Tools 3.2.0-beta4-19359-03+15b43b33901c88f68ef43f8314b5a2457716780d
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools 1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Cookiecutter 16.2.19178.1
Provides tools for finding, instantiating and customizing templates in cookiecutter format.

IntelliCode Extension 1.0
IntelliCode Visual Studio Extension Detailed Info

Microsoft Azure Tools 2.9
Microsoft Azure Tools for Microsoft Visual Studio 0x10 — v2.9.20626.2

Microsoft JVM Debugger 1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Microsoft MI-Based Debugger 1.0
Provides support for connecting Visual Studio to MI compatible debuggers

Microsoft Visual C++ Wizards 1.0
Microsoft Visual C++ Wizards

Microsoft Visual Studio VC Package 1.0
Microsoft Visual Studio VC Package

Node.js Tools 1.5.10610.1 Commit Hash:529a87de2769e143655e31ea81795c42e5775ef8
Adds support for developing and debugging Node.js apps in Visual Studio

NuGet Package Manager 5.2.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

ProjectServicesPackage Extension 1.0
ProjectServicesPackage Visual Studio Extension Detailed Info

Python 16.2.19178.1
Provides IntelliSense, projects, templates, debugging, interactive windows, and other support for Python developers.

Python — Conda support 16.2.19178.1
Conda support for Python projects.

Python — Django support 16.2.19178.1
Provides templates and integration for the Django web framework.

Python — IronPython support 16.2.19178.1
Provides templates and integration for IronPython-based projects.

Python — Profiling support 16.2.19178.1
Profiling support for Python projects.

ResourcePackage Extension 1.0
ResourcePackage Visual Studio Extension Detailed Info

ResourcePackage Extension 1.0
ResourcePackage Visual Studio Extension Detailed Info

Test Adapter for Boost.Test 1.0
Enables Visual Studio’s testing tools with unit tests written for Boost.Test. The use terms and Third Party Notices are available in the extension installation directory.

Test Adapter for Google Test 1.0
Enables Visual Studio’s testing tools with unit tests written for Google Test. The use terms and Third Party Notices are available in the extension installation directory.

TypeScript Tools 16.0.10627.2001
TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools 3.2.0-beta4-19359-03+15b43b33901c88f68ef43f8314b5a2457716780d
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual C++ for Cross Platform Mobile Development (Android) 15.0.29006.69
Visual C++ for Cross Platform Mobile Development (Android)

Visual C++ for Linux Development 1.0.9.29110
Visual C++ for Linux Development

Visual F# Tools 10.4 for F# 4.6 16.2.0-beta.19321.1+a24d94ecf97d0d69d4fbe6b8b10cd1f97737fff4
Microsoft Visual F# Tools 10.4 for F# 4.6

Visual Studio Code Debug Adapter Host Package 1.0
Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

Visual Studio Tools for CMake 1.0
Visual Studio Tools for CMake

Visual Studio Tools for CMake 1.0
Visual Studio Tools for CMake

Visual Studio Tools for Unity 4.2.0.1
Visual Studio Tools for Unity

The text was updated successfully, but these errors were encountered:

Оцените статью