Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MinGW] Fix MinGW32 build failure and almost all MinGW32/MinGW64 warnings #9268

Merged
merged 10 commits into from Jun 10, 2021

Conversation

@glx22
Copy link
Contributor

@glx22 glx22 commented May 14, 2021

Motivation / Problem

MinGW32 fails to build OpenTTD, and many warnings are generated by MinGW32 and MinGW64.

Description

First commit solves

  ../../../src/os/windows/win32.cpp: In function 'bool IsWindowsVistaOrGreater()':
D:\developpement\GitHub\glx22\OpenTTD\src\os\windows\win32.cpp(719,50): warning G0F8295B3: cast between incompatible function types from 'FARPROC' {aka 'int (__attribute__((stdcall)) *)()'} to 'LPVERIFYVERSIONINFO' {aka 'int (__attribute__((stdcall)) *)(_OSVERSIONINFOEXW*, long unsigned int, long long unsigned int)'} [-Wcast-function-type]
    719 |  static LPVERIFYVERSIONINFO _VerifyVersionInfo = (LPVERIFYVERSIONINFO)GetProcAddress(GetModuleHandle(_T("Kernel32")), "VerifyVersionInfoW");
        |                                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
D:\developpement\GitHub\glx22\OpenTTD\src\os\windows\win32.cpp(723,54): warning G0F8295B3: cast between incompatible function types from 'FARPROC' {aka 'int (__attribute__((stdcall)) *)()'} to 'LPVERSETCONDITIONMASK' {aka 'long long unsigned int (__attribute__((stdcall)) *)(long long unsigned int, long unsigned int, unsigned char)'} [-Wcast-function-type]
    723 |  static LPVERSETCONDITIONMASK _VerSetConditionMask = (LPVERSETCONDITIONMASK)GetProcAddress(GetModuleHandle(_T("Kernel32")), "VerSetConditionMask");
        |                                                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
D:\developpement\GitHub\glx22\OpenTTD\src\os\windows\win32.cpp(726,64): warning G2E6658D9: missing initializer for member '_OSVERSIONINFOEXW::wSuiteMask' [-Wmissing-field-initializers]
    726 |   OSVERSIONINFOEX osvi = { sizeof(osvi), 0, 0, 0, 0, {0}, 0, 0 };
        |                                                                ^
D:\developpement\GitHub\glx22\OpenTTD\src\os\windows\win32.cpp(726,64): warning G2E6658D9: missing initializer for member '_OSVERSIONINFOEXW::wProductType' [-Wmissing-field-initializers]
D:\developpement\GitHub\glx22\OpenTTD\src\os\windows\win32.cpp(726,64): warning G2E6658D9: missing initializer for member '_OSVERSIONINFOEXW::wReserved' [-Wmissing-field-initializers]

Second commit is just a cleanup (less LoadLibraryList() calls)

Next 3 commits are MinGW32 specific.
Third commit solves

  In file included from ../../../src/os/windows/font_win32.h:14,
                   from ../../../src/os/windows/font_win32.cpp:12:
D:\developpement\GitHub\glx22\OpenTTD\src\os\windows\win32.h(23,28): error G6B15EE17: expected identifier before numeric constant
     23 | #define SHGFP_TYPE_CURRENT 0
        |                            ^
D:\developpement\GitHub\glx22\OpenTTD\src\os\windows\win32.h(23,28): error GC66A3811: expected '}' before numeric constant
  In file included from ../../../src/os/windows/font_win32.cpp:26:
  H:/msys64/mingw32/i686-w64-mingw32/include/shlobj.h:34:14: note: to match this '{'
     34 | typedef enum {
        |              ^
  In file included from ../../../src/os/windows/font_win32.h:14,
                   from ../../../src/os/windows/font_win32.cpp:12:
D:\developpement\GitHub\glx22\OpenTTD\src\os\windows\win32.h(23,28): error G158F188C: expected unqualified-id before numeric constant
     23 | #define SHGFP_TYPE_CURRENT 0
        |                            ^
  In file included from ../../../src/os/windows/font_win32.cpp:26:
H:\msys64\mingw32\i686-w64-mingw32\include\shlobj.h(37,1): error G4B649FC0: expected declaration before '}' token
     37 | } SHGFP_TYPE;
        | ^
H:\msys64\mingw32\i686-w64-mingw32\include\shlobj.h(37,3): error GC5C65A22: 'SHGFP_TYPE' does not name a type; did you mean 'SF_TYPE'?
     37 | } SHGFP_TYPE;
        |   ^~~~~~~~~~
        |   SF_TYPE

Fourth commit solves

  ../../../src/video/win32_v.cpp: In member function 'virtual std::vector<int> VideoDriver_Win32Base::GetListOfMonitorRefreshRates()':
D:\developpement\GitHub\glx22\OpenTTD\src\video\win32_v.cpp(933,37): error G5335F942: invalid user-defined conversion from 'VideoDriver_Win32Base::GetListOfMonitorRefreshRates()::<lambda(HMONITOR, HDC, LPRECT, LPARAM)>' to 'MONITORENUMPROC' {aka 'int (__attribute__((stdcall)) *)(HMONITOR__*, HDC__*, tagRECT*, long int)'} [-fpermissive]
    933 |  }, reinterpret_cast<LPARAM>(&rates));
        |                                     ^
  ../../../src/video/win32_v.cpp:919:40: note: candidate is: 'constexpr VideoDriver_Win32Base::GetListOfMonitorRefreshRates()::<lambda(HMONITOR, HDC, LPRECT, LPARAM)>::operator BOOL (*)(HMONITOR, HDC, LPRECT, LPARAM)() const' (near match)
    919 |  EnumDisplayMonitors(nullptr, nullptr, [](HMONITOR hMonitor, HDC hDC, LPRECT rc, LPARAM data) -> BOOL {
        |                                        ^
  ../../../src/video/win32_v.cpp:919:40: note:   no known conversion from 'BOOL (*)(HMONITOR, HDC, LPRECT, LPARAM)' {aka 'int (*)(HMONITOR__*, HDC__*, tagRECT*, long int)'} to 'MONITORENUMPROC' {aka 'int (__attribute__((stdcall)) *)(HMONITOR__*, HDC__*, tagRECT*, long int)'}
  In file included from H:/msys64/mingw32/i686-w64-mingw32/include/windows.h:72,
                   from ../../../src/video/../os/windows/win32.h:13,
                   from ../../../src/video/win32_v.cpp:13:
  H:/msys64/mingw32/i686-w64-mingw32/include/winuser.h:5863:90: note:   initializing argument 3 of 'WINBOOL EnumDisplayMonitors(HDC, LPCRECT, MONITORENUMPROC, LPARAM)'
   5863 |   WINUSERAPI WINBOOL WINAPI EnumDisplayMonitors(HDC hdc,LPCRECT lprcClip,MONITORENUMPROC lpfnEnum,LPARAM dwData);
        |                                                                          ~~~~~~~~~~~~~~~~^~~~~~~~

Fifth commit solves

  ../../../src/os/windows/crashlog_win.cpp: In static member function 'static void CrashLog::InitThread()':
D:\developpement\GitHub\glx22\OpenTTD\src\os\windows\crashlog_win.cpp(643,12): warning G8178BDC9: 'safe_esp' is used uninitialized in this function [-Wuninitialized]
    643 |  _safe_esp = safe_esp;
        |  ~~~~~~~~~~^~~~~~~~~~

  cmd.exe /C "cd . && H:\msys64\mingw32\bin\g++.exe -g -mwindows @CMakeFiles\openttd.rsp -o openttd.exe -Wl,--out-implib,libopenttd.dll.a -Wl,--major-image-version,0,--minor-image-version,0  && cd ."
  H:/msys64/mingw32/bin/../lib/gcc/i686-w64-mingw32/10.3.0/../../../../i686-w64-mingw32/bin/ld.exe: CMakeFiles/openttd.dir/src/os/windows/crashlog_win.cpp.obj: in function `ZN8CrashLog10InitThreadEv':
  D:\developpement\GitHub\glx22\OpenTTD\out\build\Mingw32-Debug/../../../src/os/windows/crashlog_win.cpp:641: undefined reference to `safe_esp'
D:\developpement\GitHub\glx22\OpenTTD\out\build\Mingw32-Debug\collect2.exe : error : ld returned 1 exit status

Following commits are for MinGW32 and MinGW64
Sixth commit solves

  ../../../src/3rdparty/squirrel/squirrel/sqfuncstate.cpp: In function 'void DumpLiteral(SQObjectPtr&)':
D:\developpement\GitHub\glx22\OpenTTD\src\3rdparty\squirrel\squirrel\sqfuncstate.cpp(88,27): warning G479D744D: format '%d' expects argument of type 'int', but argument 2 has type 'SQInteger' {aka 'long long int'} [-Wformat=]
     88 |   case OT_INTEGER: printf("{" OTTD_PRINTF64 "}",_integer(o));break;
        |                           ^~~~~~~~~~~~~~~~~~~~~
  In file included from ../../../src/3rdparty/squirrel/squirrel/sqfuncstate.cpp:5:
  D:/developpement/GitHub/glx22/OpenTTD/src/stdafx.h:303:31: note: format string is defined here
    303 | #   define OTTD_PRINTF64 "%I64d"
        |                           ~~~~^
        |                               |
        |                               int
        |                           %I64lld

Seventh commit solves

  ../../../src/os/windows/string_uniscribe.cpp: In function 'HFONT__* HFontFromFont(Font*)':
D:\developpement\GitHub\glx22\OpenTTD\src\os\windows\string_uniscribe.cpp(147,68): warning GBB422243: cast from type 'const void*' to type 'PLOGFONT' {aka 'tagLOGFONTW*'} casts away qualifiers [-Wcast-qual]
    147 |  if (font->fc->GetOSHandle() != nullptr) return CreateFontIndirect((const PLOGFONT)font->fc->GetOSHandle());
        |                                                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
D:\developpement\GitHub\glx22\OpenTTD\src\os\windows\string_uniscribe.cpp(147,68): warning GCB925CEF: type qualifiers ignored on cast result type [-Wignored-qualifiers]

Eighth commit solves

  ../../../src/os/windows/win32.cpp: In function 'bool LoadLibraryList(void (**)(int), const char*)':
D:\developpement\GitHub\glx22\OpenTTD\src\os\windows\win32.cpp(70,14): warning G0F8295B3: cast between incompatible function types from 'FARPROC' {aka 'int (__attribute__((stdcall)) *)()'} to 'Function' {aka 'void (*)(int)'} [-Wcast-function-type]
     70 |    *proc++ = (Function)p;
        |              ^~~~~~~~~~~
  ../../../src/os/windows/win32.cpp: In function 'int OTTDStringCompare(const char*, const char*)':
D:\developpement\GitHub\glx22\OpenTTD\src\os\windows\win32.cpp(682,22): warning G0F8295B3: cast between incompatible function types from 'FARPROC' {aka 'int (__attribute__((stdcall)) *)()'} to 'PFNCOMPARESTRINGEX' {aka 'int (__attribute__((stdcall)) *)(const wchar_t*, long unsigned int, const wchar_t*, int, const wchar_t*, int, void*, void*, long int)'} [-Wcast-function-type]
    682 |   _CompareStringEx = (PFNCOMPARESTRINGEX)GetProcAddress(GetModuleHandle(L"Kernel32"), "CompareStringEx");
        |                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  ../../../src/video/win32_v.cpp: In member function 'virtual float VideoDriver_Win32Base::GetDPIScale()':
D:\developpement\GitHub\glx22\OpenTTD\src\video\win32_v.cpp(959,22): warning G0F8295B3: cast between incompatible function types from 'FARPROC' {aka 'int (__attribute__((stdcall)) *)()'} to 'PFNGETDPIFORWINDOW' {aka 'unsigned int (__attribute__((stdcall)) *)(HWND__*)'} [-Wcast-function-type]
    959 |   _GetDpiForWindow = (PFNGETDPIFORWINDOW)GetProcAddress(GetModuleHandle(L"User32"), "GetDpiForWindow");
        |                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
(+ line 960 GetDpiForSystem for MinGW64)
D:\developpement\GitHub\glx22\OpenTTD\src\video\win32_v.cpp(961,23): warning G0F8295B3: cast between incompatible function types from 'FARPROC' {aka 'int (__attribute__((stdcall)) *)()'} to 'PFNGETDPIFORMONITOR' {aka 'long int (__attribute__((stdcall)) *)(HMONITOR__*, int, unsigned int*, unsigned int*)'} [-Wcast-function-type]
    961 |   _GetDpiForMonitor = (PFNGETDPIFORMONITOR)GetProcAddress(LoadLibrary(L"Shcore.dll"), "GetDpiForMonitor");
        |                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  ../../../src/os/windows/font_win32.cpp: In function 'void LoadWin32Font(FontSize)':
D:\developpement\GitHub\glx22\OpenTTD\src\os\windows\font_win32.cpp(623,57): warning G0F8295B3: cast between incompatible function types from 'FARPROC' {aka 'int (__attribute__((stdcall)) *)()'} to 'PFNGETFONTRESOURCEINFO' {aka 'int (__attribute__((stdcall)) *)(const wchar_t*, long unsigned int*, void*, long unsigned int)'} [-Wcast-function-type]
    623 |     static PFNGETFONTRESOURCEINFO GetFontResourceInfo = (PFNGETFONTRESOURCEINFO)GetProcAddress(GetModuleHandle(L"Gdi32"), "GetFontResourceInfoW");
        |                                                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Ninth commit solves

  ../../../src/video/win32_v.cpp: In function 'void LoadWGLExtensions()':
D:\developpement\GitHub\glx22\OpenTTD\src\video\win32_v.cpp(1267,65): warning G0F8295B3: cast between incompatible function types from 'PROC' {aka 'int (__attribute__((stdcall)) *)()'} to 'PFNWGLGETEXTENSIONSSTRINGARBPROC' {aka 'const char* (__attribute__((stdcall)) *)(HDC__*)'} [-Wcast-function-type]
   1267 |    PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress("wglGetExtensionsStringARB");
        |                                                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
D:\developpement\GitHub\glx22\OpenTTD\src\video\win32_v.cpp(1272,36): warning G0F8295B3: cast between incompatible function types from 'PROC' {aka 'int (__attribute__((stdcall)) *)()'} to 'PFNWGLCREATECONTEXTATTRIBSARBPROC' {aka 'HGLRC__* (__attribute__((stdcall)) *)(HDC__*, HGLRC__*, const int*)'} [-Wcast-function-type]
   1272 |      _wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)wglGetProcAddress("wglCreateContextAttribsARB");
        |                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
D:\developpement\GitHub\glx22\OpenTTD\src\video\win32_v.cpp(1276,28): warning G0F8295B3: cast between incompatible function types from 'PROC' {aka 'int (__attribute__((stdcall)) *)()'} to 'PFNWGLSWAPINTERVALEXTPROC' {aka 'int (__attribute__((stdcall)) *)(int)'} [-Wcast-function-type]
   1276 |      _wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT");
        |                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

And last commit solves a build failure introduced recently.

Limitations

There's a remaining warning for MinGW32 release build, displayed at link time

  ../../../src/os/windows/font_win32.cpp: In function 'LoadWin32Font':
D:\developpement\GitHub\glx22\OpenTTD\src\os\windows\font_win32.cpp(630,33): warning GAE84912C: argument to 'alloca' may be too large [-Walloca-larger-than=]
    630 |       LOGFONT *buf = (LOGFONT *)AllocaM(byte, len);
        |                                 ^

Checklist for review

Some things are not automated, and forgotten often. This list is a reminder for the reviewers.

  • The bug fix is important enough to be backported? (label: 'backport requested')
  • This PR affects the save game format? (label 'savegame upgrade')
  • This PR affects the GS/AI API? (label 'needs review: Script API')
    • ai_changelog.hpp, gs_changelog.hpp need updating.
    • The compatibility wrappers (compat_*.nut) need updating.
  • This PR affects the NewGRF API? (label 'needs review: NewGRF')
Copy link
Contributor

@rubidium42 rubidium42 left a comment

I've got no clue about the DLL code, though it does not look obviously wrong.
The last commit smells a bit as I wouldn't expect the function parameters to be that different.

Regarding the last warning, might there be something wrong with the definition of LOGFONT so that is really big with MinGW?

src/os/windows/crashlog_win.cpp Outdated Show resolved Hide resolved
src/os/windows/win32.cpp Outdated Show resolved Hide resolved
src/os/windows/win32.cpp Outdated Show resolved Hide resolved
src/os/windows/crashlog_win.cpp Outdated Show resolved Hide resolved
@glx22 glx22 force-pushed the glx22:mingw_fixes branch from 5eea1a1 to e9bb921 May 20, 2021
@glx22 glx22 force-pushed the glx22:mingw_fixes branch from e9bb921 to 8e6eeb3 Jun 10, 2021
@glx22 glx22 merged commit c2db408 into OpenTTD:master Jun 10, 2021
13 checks passed
13 checks passed
@github-actions
Emscripten
Details
@github-actions
Commit checker
Details
@github-actions
Check preview needs update Check preview needs update
Details
@github-actions
Linux (clang, clang++, libsdl2-dev)
Details
@github-actions
Linux (gcc, g++, libsdl2-dev)
Details
@github-actions
Linux (gcc, g++, libsdl1.2-dev)
Details
@github-actions
Linux (gcc, g++, -DOPTION_DEDICATED=ON)
Details
@github-actions
Mac OS (x64, x86_64)
Details
@github-actions
Windows (windows-latest, x86)
Details
@github-actions
Windows (windows-latest, x64)
Details
@github-actions
Windows (windows-2016, x86)
Details
@github-actions
Windows (windows-2016, x64)
Details
@github-actions
Check Annotations
Details
@glx22 glx22 deleted the glx22:mingw_fixes branch Jun 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants