| Summary: | Windows build fails due to conflicting types for 'XINPUT_GAMEPAD_EX' | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Mario Emmenlauer <mario> |
| Component: | *don't know* | Assignee: | Sam Lantinga <slouken> |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | normal | ||
| Priority: | P2 | CC: | mario, sezeroz, superfury |
| Version: | 2.0.5 | ||
| Hardware: | x86_64 | ||
| OS: | Windows 7 | ||
| Attachments: | mingw xinput configury patch | ||
|
Description
Mario Emmenlauer
2017-03-17 09:44:40 UTC
This seems to affect more MSYS2 users now. I've managed to fix this on MinGW-w64(gcc version 6.3.0) and MinGW 32-bit(gcc version 5.3.0) by modifiying the SDL_XInput.h, by wrapping the two type definitions within a #ifndef to make it not define those structures on version 6.3.0+(Don't know the exact version when these defines are added, since I don't know the version of the commit adding it to the SDL):
------------------------------------------
/* typedef's for XInput structs we use */
#ifdef __MINGW32__
#if ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((6) << 16) + (3))
//We're defined on gcc 6.3+(MinGW)
#define HAS_XINPUT_GAMEPAD_EX
#define HAS_XINPUT_STATE_EX
#endif
#endif
#ifndef HAS_XINPUT_GAMEPAD_EX
typedef struct
{
WORD wButtons;
BYTE bLeftTrigger;
BYTE bRightTrigger;
SHORT sThumbLX;
SHORT sThumbLY;
SHORT sThumbRX;
SHORT sThumbRY;
DWORD dwPaddingReserved;
} XINPUT_GAMEPAD_EX;
#endif
#ifndef HAS_XINPUT_STATE_EX
typedef struct
{
DWORD dwPacketNumber;
XINPUT_GAMEPAD_EX Gamepad;
} XINPUT_STATE_EX;
#endif
------------------------------------------
Although, it's just a little wrapper for version 6.3.0+ MinGW to not use those type definitions(as it should be in the headers already). The 32-bit version (according to the MinGW installation manager) is 5.0.3-3(which is the repository version according to the MinGW installation manager).
Btw, I've applied this to the current SDL2 mecurial code. The update adding this to the MinGW headers seems to be https://sourceforge.net/p/mingw-w64/mingw-w64/ci/c628bd49a2c8cdee2250430c8d7b7cd95f1fe90a . The current SDL2 mecurial commit seems to be https://hg.libsdl.org/SDL/rev/7860594a8ad7 . Thanks a lot! I'll test when I find a bit of time. So do we need to do something now, or is this taken care of for MingW64 users on their end of things? --ryan. (In reply to Ryan C. Gordon from comment #5) > So do we need to do something now, or is this taken care of for MingW64 > users on their end of things? > > --ryan. I think it would either need to be added to MinGW32(to increase compatibility, with a newer gcc compiler version, upgrading the toolchain), or added to SDL2 for compatibility with the older gcc version(MinGW32). Adding the fix to SDL2 would fix both older and newer compiler versions, both on x86 and x64 versions. Although I don't know at what version the https://sourceforge.net/p/mingw-w64/mingw-w64/ci/c628bd49a2c8cdee2250430c8d7b7cd95f1fe90a commit was implemented in, nor for a proper way to detect it(other than the 6.3.* compiler version detection). (In reply to superfury from comment #6) > (In reply to Ryan C. Gordon from comment #5) > > So do we need to do something now, or is this taken care of for MingW64 > > users on their end of things? > > > > --ryan. > > I think it would either need to be added to MinGW32(to increase > compatibility, with a newer gcc compiler version, upgrading the toolchain), > or added to SDL2 for compatibility with the older gcc version(MinGW32). > Adding the fix to SDL2 would fix both older and newer compiler versions, > both on x86 and x64 versions. Although I don't know at what version the > https://sourceforge.net/p/mingw-w64/mingw-w64/ci/ > c628bd49a2c8cdee2250430c8d7b7cd95f1fe90a commit was implemented in, nor for > a proper way to detect it(other than the 6.3.* compiler version detection). Looking the fault itself up, it seems to have been around since about version 5.0.2, but not all of those compilers based on that version seem have it. So maybe on all versions higher than 5.0.2, apply this update(define those two defines)? Sorry that I lost track: is the fix already in trunk? Or should I make a small patch for MSYS2 for the time being? Thanks a lot for your help! I've put this patch in as https://hg.libsdl.org/SDL/rev/117d4ce1390e ...can you verify this works on the latest MinGW? Thanks, --ryan. (In reply to Ryan C. Gordon from comment #9) > I've put this patch in as https://hg.libsdl.org/SDL/rev/117d4ce1390e ...can > you verify this works on the latest MinGW? > > Thanks, > --ryan. This patch is wrong: the structure in question has nothing to do with any gcc version in use. I suggest reverting this adding a conigury check for it, instead. Something like the following should do it: (configure needs regenerating.) diff -r 8a29b371e2db CMakeLists.txt --- a/CMakeLists.txt Tue Jun 06 14:06:40 2017 -0400 +++ b/CMakeLists.txt Tue Jun 06 23:21:42 2017 +0300 @@ -1092,6 +1092,16 @@ #include <windows.h> #include <xinput.h> int main(int argc, char **argv) { }" HAVE_XINPUT_H) + check_c_source_compiles(" + #include <windows.h> + #include <xinput.h> + XINPUT_GAMEPAD_EX x1; + int main(int argc, char **argv) { }" HAVE_XINPUT_GAMEPAD_EX) + check_c_source_compiles(" + #include <windows.h> + #include <xinput.h> + XINPUT_STATE_EX s1; + int main(int argc, char **argv) { }" HAVE_XINPUT_STATE_EX) else() check_include_file(xinput.h HAVE_XINPUT_H) endif() diff -r 8a29b371e2db configure.in --- a/configure.in Tue Jun 06 14:06:40 2017 -0400 +++ b/configure.in Tue Jun 06 23:21:42 2017 +0300 @@ -2716,6 +2716,16 @@ AC_CHECK_HEADER(dxgi.h, have_dxgi=yes) AC_CHECK_HEADER(xaudio2.h, have_xaudio2=yes) AC_CHECK_HEADER(xinput.h, have_xinput=yes) + AC_TRY_COMPILE([ +#include <windows.h> +#include <xinput.h> +XINPUT_GAMEPAD_EX x1; + ],[],[have_xinput_gamepadex=yes]) + AC_TRY_COMPILE([ +#include <windows.h> +#include <xinput.h> +XINPUT_STATE_EX s1; + ],[],[have_xinput_stateex=yes]) if test x$have_ddraw = xyes; then AC_DEFINE(HAVE_DDRAW_H, 1, [ ]) @@ -2732,6 +2742,12 @@ if test x$have_xinput = xyes; then AC_DEFINE(HAVE_XINPUT_H, 1, [ ]) fi + if test x$have_xinput_gamepadex = xyes; then + AC_DEFINE(HAVE_XINPUT_GAMEPAD_EX, 1, [ ]) + fi + if test x$have_xinput_stateex = xyes; then + AC_DEFINE(HAVE_XINPUT_STATE_EX, 1, [ ]) + fi SUMMARY_video="${SUMMARY_video} directx" SUMMARY_audio="${SUMMARY_audio} directx" diff -r 8a29b371e2db include/SDL_config.h.cmake --- a/include/SDL_config.h.cmake Tue Jun 06 14:06:40 2017 -0400 +++ b/include/SDL_config.h.cmake Tue Jun 06 23:21:42 2017 +0300 @@ -55,6 +55,8 @@ #cmakedefine HAVE_XAUDIO2_H @HAVE_XAUDIO2_H@ #cmakedefine HAVE_XINPUT_H @HAVE_XINPUT_H@ #cmakedefine HAVE_DXGI_H @HAVE_DXGI_H@ +#cmakedefine HAVE_XINPUT_GAMEPAD_EX @HAVE_XINPUT_GAMEPAD_EX@ +#cmakedefine HAVE_XINPUT_STATE_EX @HAVE_XINPUT_STATE_EX@ /* Comment this if you want to build without any C library requirements */ #cmakedefine HAVE_LIBC 1 diff -r 8a29b371e2db include/SDL_config.h.in --- a/include/SDL_config.h.in Tue Jun 06 14:06:40 2017 -0400 +++ b/include/SDL_config.h.in Tue Jun 06 23:21:42 2017 +0300 @@ -55,6 +55,8 @@ #undef HAVE_DSOUND_H #undef HAVE_DXGI_H #undef HAVE_XINPUT_H +#undef HAVE_XINPUT_GAMEPAD_EX +#undef HAVE_XINPUT_STATE_EX /* Comment this if you want to build without any C library requirements */ #undef HAVE_LIBC diff -r 8a29b371e2db include/SDL_config_windows.h --- a/include/SDL_config_windows.h Tue Jun 06 14:06:40 2017 -0400 +++ b/include/SDL_config_windows.h Tue Jun 06 23:21:42 2017 +0300 @@ -82,6 +82,8 @@ #define HAVE_DSOUND_H 1 #define HAVE_DXGI_H 1 #define HAVE_XINPUT_H 1 +#define HAVE_XINPUT_GAMEPAD_EX 1 +#define HAVE_XINPUT_STATE_EX 1 /* This is disabled by default to avoid C runtime dependencies and manifest requirements */ #ifdef HAVE_LIBC diff -r 8a29b371e2db src/core/windows/SDL_xinput.h --- a/src/core/windows/SDL_xinput.h Tue Jun 06 14:06:40 2017 -0400 +++ b/src/core/windows/SDL_xinput.h Tue Jun 06 23:21:42 2017 +0300 @@ -101,13 +101,7 @@ /* typedef's for XInput structs we use */ -/* Don't redeclare these on MinGW with gcc >= 5.0.2 */ -#if defined(__MINGW32__) && (((__GNUC__ * 10000) + (__GNUC_MINOR__ * 100) + __GNUC_PATCHLEVEL__) >= 50002) -#define HAS_XINPUT_GAMEPAD_EX -#define HAS_XINPUT_STATE_EX -#endif - -#ifndef HAS_XINPUT_GAMEPAD_EX +#ifndef HAVE_XINPUT_GAMEPAD_EX typedef struct { WORD wButtons; @@ -121,7 +115,7 @@ } XINPUT_GAMEPAD_EX; #endif -#ifndef HAS_XINPUT_STATE_EX +#ifndef HAVE_XINPUT_STATE_EX typedef struct { DWORD dwPacketNumber; Created attachment 2754 [details]
mingw xinput configury patch
Here is a proper patch (attached) with configure regenerated too.
(In reply to Ozkan Sezer from comment #11) > Created attachment 2754 [details] > mingw xinput configury patch > > Here is a proper patch (attached) with configure regenerated too. Confirmed working on MinGW64(gcc 6.3.0). MinGW32 compiles with errors straight after configuring: *** START DUMP *** $ make /bin/sh ../build-scripts/mkinstalldirs build mkdir -p -- build /bin/sh ../build-scripts/updaterev.sh CC build/SDL.lo In file included from ../src/SDL.c:24:0: ../src/core/windows/SDL_windows.h:67:28: error: unknown type name 'REFIID' extern BOOL WIN_IsEqualIID(REFIID a, REFIID b); ^ ../src/core/windows/SDL_windows.h:67:38: error: unknown type name 'REFIID' extern BOOL WIN_IsEqualIID(REFIID a, REFIID b); ^ make: *** [build/SDL.lo] Error 1 *** END DUMP *** I compile it as given below to try to make it not depend on any special dll files in Windows(Windows 95-compatible). Building on MinGW 32-bit(fails with the above error): ./configure --prefix=/mingw CFLAGS="-g -O3 -DUSING_GENERATED_CONFIG_H -static-libgcc -static-libstdc++" Building on MinGW 64-bit(succeeds without errors): ./configure --prefix=/mingw CFLAGS="-g -O3 -DUSING_GENERATED_CONFIG_H -static-libgcc -static-libstdc++" --host=x86_64-w64-mingw32 (In reply to superfury from comment #12) > (In reply to Ozkan Sezer from comment #11) > > Created attachment 2754 [details] > > mingw xinput configury patch > > > > Here is a proper patch (attached) with configure regenerated too. > > Confirmed working on MinGW64(gcc 6.3.0). Thanks for confirming. I suggest that this patch be applied to hg. > MinGW32 compiles with errors straight after configuring: > > *** START DUMP *** > $ make > /bin/sh ../build-scripts/mkinstalldirs build > mkdir -p -- build > /bin/sh ../build-scripts/updaterev.sh > CC build/SDL.lo > In file included from ../src/SDL.c:24:0: > ../src/core/windows/SDL_windows.h:67:28: error: unknown type name 'REFIID' > extern BOOL WIN_IsEqualIID(REFIID a, REFIID b); Several headers from mingw.org are very broken. The specific error you report can be fixed by including basetyps.h. Like so: diff -r 5f33dc4d399e src/core/windows/SDL_windows.h --- a/src/core/windows/SDL_windows.h Sun Jun 18 23:00:42 2017 +0200 +++ b/src/core/windows/SDL_windows.h Tue Jun 20 08:55:02 2017 +0300 @@ -35,6 +35,7 @@ #endif #include <windows.h> +#include <basetyps.h> /* for REFIID with broken mingw.org headers */ /* Routines to convert from UTF8 to native Windows text */ #if UNICODE PING ? Fixed, thanks! https://hg.libsdl.org/SDL/rev/c936a84f05ba |