Error C2338 when compiling clean source.

  • biran4454
    16th Nov 2019 Member 0 Permalink

    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.)

    Thanks!

     

    EDIT:

    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'.

    Edited once by biran4454. Last: 20th Nov 2019
  • jacob1
    16th Nov 2019 Developer 0 Permalink
    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
    Edited once by jacob1. Last: 16th Nov 2019
  • biran4454
    17th Nov 2019 Member 0 Permalink

    @jacob1 (View Post)

     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.

    Thanks again!

     

    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.

    Thanks!

     

    Edited 2 times by biran4454. Last: 17th Nov 2019
  • jacob1
    17th Nov 2019 Developer 0 Permalink
    @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.
  • biran4454
    17th Nov 2019 Member 0 Permalink

    @jacob1 (View Post)

     '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.

    Thanks!

  • jacob1
    17th Nov 2019 Developer 0 Permalink
    @biran4454 (View Post)
    Can you please post the entire compile log, and paste it to https://bpaste.net/ ?
  • biran4454
    17th Nov 2019 Member 0 Permalink

    @jacob1 (View Post)

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

    Thanks!

  • jacob1
    17th Nov 2019 Developer 0 Permalink
    @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.
  • biran4454
    19th Nov 2019 Member 0 Permalink

    OK, I'll try that. Thanks!

     

    EDIT:

    Brilliant, all working now!

    Thanks so much!

     

    EDIT 2:

    I have just added a new element called TEST via. newelement.py, and get this error.

    Thanks!

    Edited 4 times by biran4454. Last: 20th Nov 2019