[PATCH] Fix M_PI with -std=c++11 on Mingw

Lubomir I. Ivanov neolit123 at gmail.com
Tue Nov 3 03:47:28 PST 2015


From: "Lubomir I. Ivanov" <neolit123 at gmail.com>

The introduction of -std=c++11 breaks usage of M_PI in Mingw,
but technically M_PI is not standard C or C++.

Defining M_PI in units.h solves the issue.

Signed-off-by: Lubomir I. Ivanov <neolit123 at gmail.com>
---
the Mingw math.h header does have the _USE_MATH_DEFINES
macro check and it's one of the ways to get M_PI defined.

so, i've tried doing it the proper way:
-- #define _USE_MATH_DEFINES
-- #include <math.h>

..in all locations where we have <math.h> and M_PI, but it doesn't
work! something, somehwhere is undefining _USE_MATH_DEFINES
and i don't have a good solution.
---
 subsurface-core/units.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/subsurface-core/units.h b/subsurface-core/units.h
index 1273bd9..9d1b0fc 100644
--- a/subsurface-core/units.h
+++ b/subsurface-core/units.h
@@ -2,6 +2,9 @@
 #define UNITS_H
 
 #include <math.h>
+#ifndef M_PI
+#define M_PI 3.14159265358979323846
+#endif
 
 #ifdef __cplusplus
 extern "C" {
-- 
1.7.11.msysgit.0



More information about the subsurface mailing list