[Scummvm-tracker] [ScummVM :: Bugs] #11380: WIN32: Error when building with MSVC 2019

ScummVM :: Bugs trac at scummvm.org
Mon Mar 9 13:54:11 UTC 2020


#11380: WIN32: Error when building with MSVC 2019
----------------------------+-------------------------
  Reporter:  carlo-bramini  |      Owner:  (none)
      Type:  defect         |     Status:  new
  Priority:  normal         |  Component:  Port: Win32
Resolution:                 |   Keywords:
      Game:                 |
----------------------------+-------------------------
Comment (by carlo-bramini):

 I tried to do some debugging and I discovered the cause of the problem.
 It is a bug inside SDL_syswm.h.
 The SDL_syswm.h does these actions:
 1) includes some SDL files.
 2) includes begin_code.h, which changes default packing with #pragma pack.

 3) adds extern "C" { if it is C++
 4) includes files like windows.h or X server or others.
 5) declare some SDL stuff
 6) closes previously opened extern "C".
 7) includes close_code.h

 The problem comes out because windows.h is included after changing with
 #pragma pack.
 Evidently, Windows SDK headers do not like to be included in that way with
 Visual Studio 2019.
 So, the solutions are actually:

 - Fixing SDL_syswm.h so that system headers are included before all
 others, which should be the best thing:

 1) includes files like windows.h or X server or others.
 2) includes some SDL files.
 3) includes begin_code.h, which changes default packing with #pragma pack.
 4) adds extern "C" { if it is C++
 5) declare some SDL stuff
 6) closes previously opened extern "C".
 7) includes close_code.h

 - Including windows.h before including SDL_syswm.h inside SCUMMVM
 backends/platform/sdl/sdl-sys.h.
 I did this patch in my sources:


 {{{
 --- a/backends/platform/sdl/sdl-sys.h
 +++ b/backends/platform/sdl/sdl-sys.h
 @@ -144,6 +144,13 @@
  #include <SDL.h>
  #endif

 +#ifdef _WIN32
 +#ifndef WIN32_LEAN_AND_MEAN
 +#define WIN32_LEAN_AND_MEAN 1
 +#endif
 +#include <windows.h>
 +#endif // _WIN32
 +
  // Ignore warnings from system headers pulled by SDL
  #pragma warning(push)
  #pragma warning(disable:4121) // alignment of a member was sensitive to
 packing
 }}}


 Perhaps, this patch could be added to the sources with a remark, and
 signal this thing to developers of SDL2. When it will be solved in their
 master branch, the patch could be safely removed from the code.
 Alternatively, since you provide a set of precompiled libraries to be used
 with VisualStudio (download link is also in the wiki), you could correct
 SDL_syswm.h yourself, this also fix the problem is a rapid manner without
 committing the above patch.

 Sincerely.
-- 
Ticket URL: <https://bugs.scummvm.org/ticket/11380#comment:3>
ScummVM :: Bugs <https://bugs.scummvm.org>
ScummVM


More information about the Scummvm-tracker mailing list