From d4a0bf86d688d1b68e00ff302858de5a4e0d9727 Mon Sep 17 00:00:00 2001 From: Keir Mierle Date: Sun, 24 Feb 2013 10:35:44 -0800 Subject: [PATCH] Fix threading build on Windows. On Windows, including the "windows.h" header defines an enormous number of symbols; some of which are macros with common names. In particular, "ERROR" and "min" and "max" get defined. This causes clashes when user code references these names in a context other than the intended use in windows.h. To deal with this, the Microsoft engineers added the ability to control the definition of these symbols by adding extra defines. In particular, including windows.h in the following way #define NOGDI #define NOMINMAX will reduce the number of macros defined. This way they will not conflict with other uses in Ceres. For example, numeric_limits::max() is impossible to call without defining NOMINMAX. Change-Id: I166f5d3bb6dc0e2e4b2ebf800fb19e49206f7874 --- internal/ceres/mutex.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/internal/ceres/mutex.h b/internal/ceres/mutex.h index 5090a71b7..410748ff0 100644 --- a/internal/ceres/mutex.h +++ b/internal/ceres/mutex.h @@ -107,10 +107,12 @@ # define _WIN32_WINNT 0x0400 # endif # endif +// Unfortunately, windows.h defines a bunch of macros with common +// names. Two in particular need avoiding: ERROR and min/max. // To avoid macro definition of ERROR. -# define CERES_NOGDI +# define NOGDI // To avoid macro definition of min/max. -# define CERES_NOMINMAX +# define NOMINMAX # include typedef CRITICAL_SECTION MutexType; #elif defined(CERES_HAVE_PTHREAD) && defined(CERES_HAVE_RWLOCK)