diff --git a/CHANGES b/CHANGES index 2310d895b..bd5c2beba 100644 --- a/CHANGES +++ b/CHANGES @@ -3,6 +3,8 @@ CHANGES IN FLTK 1.3.5 RELEASED: ??? ?? 2017 Bug fixes and other improvements + - Fix a MinGW build error with new MinGW versions as of Feb 2018 + (undefined S_OK and __FD_ISSET), see STR #3454. - Windows/CMake: Add missing definition of WIN32 for Windows builds. This seems to be necessary for VS2017 and other compilers that don't #define WIN32, but FLTK relies on this preprocessor macro. diff --git a/src/Fl.cxx b/src/Fl.cxx index 597524b86..f580159f3 100644 --- a/src/Fl.cxx +++ b/src/Fl.cxx @@ -3,7 +3,7 @@ // // Main event handling code for the Fast Light Tool Kit (FLTK). // -// Copyright 1998-2015 by Bill Spitzak and others. +// Copyright 1998-2018 by Bill Spitzak and others. // // This library is free software. Distribution and use rights are outlined in // the file "COPYING" which should have been included with this file. If this @@ -39,8 +39,24 @@ # endif #endif + +// STR #3454: We must #define FD_ISSET before we #include winsock2.h +// to fix an undefined reference (__FD_ISSET). (AlbrechtS Feb 2018) +// Other portions of the fix for STR #3454 are in src/Fl_win32.cxx. +// This fix is only necessary for MinGW. + +#ifdef __MINGW32__ +static void * get_wsock_mod(); +typedef int(__stdcall *fl_wsk_fd_is_set_f)(unsigned int, void *); +static fl_wsk_fd_is_set_f fl_wsk_fd_is_set = 0; + +#define FD_ISSET(S,SET) \ + (get_wsock_mod() ? fl_wsk_fd_is_set(S, SET) : 0) +#endif // __MINGW32__ + // recent versions of MinGW warn: "Please include winsock2.h before windows.h", // hence we must include winsock2.h before FL/Fl.H (A.S. Dec. 2010, IMM May 2011) + #if defined(WIN32) && !defined(__CYGWIN__) # include #endif diff --git a/src/Fl_win32.cxx b/src/Fl_win32.cxx index 2c49ea010..2c0f2339b 100644 --- a/src/Fl_win32.cxx +++ b/src/Fl_win32.cxx @@ -3,7 +3,7 @@ // // WIN32-specific code for the Fast Light Tool Kit (FLTK). // -// Copyright 1998-2016 by Bill Spitzak and others. +// Copyright 1998-2018 by Bill Spitzak and others. // // This library is free software. Distribution and use rights are outlined in // the file "COPYING" which should have been included with this file. If this @@ -60,6 +60,11 @@ #include #include +// New versions of MinGW (as of Feb 2018) need to include winerror.h to +// #define S_OK which used to be defined in ole2.h (STR #3454) + +#include + // // USE_ASYNC_SELECT - define it if you have WSAAsyncSelect()... // USE_ASYNC_SELECT is OBSOLETED in 1.3 for the following reasons: @@ -100,14 +105,24 @@ static bool initial_clipboard = true; // note: winsock2.h has been #include'd in Fl.cxx #define WSCK_DLL_NAME "WS2_32.DLL" +// Patch for MinGW (__MINGW32__): see STR #3454 and src/Fl.cxx +#ifdef __MINGW32__ +typedef int(WINAPI *fl_wsk_fd_is_set_f)(unsigned int, void *); +#else +typedef int(WINAPI *fl_wsk_fd_is_set_f)(SOCKET, fd_set *); +static fl_wsk_fd_is_set_f fl_wsk_fd_is_set = 0; +#endif + typedef int (WINAPI* fl_wsk_select_f)(int, fd_set*, fd_set*, fd_set*, const struct timeval*); -typedef int (WINAPI* fl_wsk_fd_is_set_f)(SOCKET, fd_set *); static HMODULE s_wsock_mod = 0; static fl_wsk_select_f s_wsock_select = 0; -static fl_wsk_fd_is_set_f fl_wsk_fd_is_set = 0; +#ifdef __MINGW32__ +static void * get_wsock_mod() { +#else static HMODULE get_wsock_mod() { +#endif if (!s_wsock_mod) { s_wsock_mod = LoadLibrary(WSCK_DLL_NAME); if (s_wsock_mod==NULL)