From 8c572c0a771cc46e9c98f10ae08bb83e9ed58acd Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 24 Aug 2017 13:55:23 +0200 Subject: [PATCH] Always include wx/msw/winundef.h from wx/defs.h, not just once Fix compilation/link problems due to symbols redefinitions in user code that could happen if it included some wx header first, then (possibly indirectly, e.g. via another third party library) and then another wx header -- in this case, the second wx header wasn't protected from redefinitions resulting in all the usual problems. Avoid this by always including winundef.h whenever any wx header is included, not just when wx/defs.h is included for the first time. --- include/wx/defs.h | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/include/wx/defs.h b/include/wx/defs.h index cc07065a7d..19a22cc39d 100644 --- a/include/wx/defs.h +++ b/include/wx/defs.h @@ -10,6 +10,31 @@ /* THIS IS A C FILE, DON'T USE C++ FEATURES (IN PARTICULAR COMMENTS) IN IT */ +/* + We want to avoid compilation and, even more perniciously, link errors if + the user code includes before include wxWidgets headers. These + error happen because #define's many common symbols, such as + Yield or GetClassInfo, which are also used in wxWidgets API. Including our + "cleanup" header below un-#defines them to fix this. + + Moreover, notice that it is also possible for the user code to include some + wx header (this including wx/defs.h), then include and then + include another wx header. To avoid the problem for the second header + inclusion, we must include wx/msw/winundef.h from here always and not just + during the first inclusion, so it has to be outside of _WX_DEFS_H_ guard + check below. + */ +#ifdef __cplusplus + /* + Test for WIN32, defined by windows.h itself, not our own __WINDOWS__, + which is not defined yet. + */ +# ifdef WIN32 +# include "wx/msw/winundef.h" +# endif /* WIN32 */ +#endif /* __cplusplus */ + + #ifndef _WX_DEFS_H_ #define _WX_DEFS_H_ @@ -3294,16 +3319,6 @@ typedef const void* WXWidget; #include "wx/qt/defs.h" #endif -/* This is required because of clashing macros in windows.h, which may be */ -/* included before or after wxWidgets classes, and therefore must be */ -/* disabled here before any significant wxWidgets headers are included. */ -#ifdef __cplusplus -#ifdef __WINDOWS__ -#include "wx/msw/winundef.h" -#endif /* __WINDOWS__ */ -#endif /* __cplusplus */ - - /* include the feature test macros */ #include "wx/features.h"