warning C4005: “M_PI”: macro redefined

815 views
Skip to first unread message

Yili Zhao

unread,
Mar 31, 2015, 9:48:00 PM3/31/15
to wx-u...@googlegroups.com
Hi,
  when compiling an app with wxWidgets 3.0.2 by Visual Studio 2013, there is a warning:

c:\program files (x86)\microsoft visual studio 12.0\vc\include\math.h(1298): warning C4005: “M_PI”: macro redefined
1>          d:\sdk\wxwidgets-3.0.2\include\wx\math.h(21) : see previous definition of 'M_PI'

// wxWidgets's math.h

#include <math.h>

#ifndef M_PI
    #define M_PI 3.1415926535897932384626433832795
#endif

In VS math.h, there is : #define M_PI       3.14159265358979323846

So it should not generate this warning, but it did.

How can I solve this issue?
Thanks!


Vadim Zeitlin

unread,
Apr 1, 2015, 8:12:16 AM4/1/15
to wx-u...@googlegroups.com
On Tue, 31 Mar 2015 18:48:00 -0700 (PDT) Yili Zhao wrote:

YZ> Hi,
YZ> when compiling an app with wxWidgets 3.0.2 by Visual Studio 2013, there
YZ> is a warning:
YZ>
YZ> c:\program files (x86)\microsoft visual studio
YZ> 12.0\vc\include\math.h(1298): warning C4005: “M_PI”: macro redefined
YZ> 1> d:\sdk\wxwidgets-3.0.2\include\wx\math.h(21) : see previous
YZ> definition of 'M_PI'
YZ>
YZ> // wxWidgets's math.h
YZ>
YZ> #include <math.h>
YZ>
YZ> #ifndef M_PI
YZ> #define M_PI 3.1415926535897932384626433832795
YZ> #endif
YZ>
YZ> In VS math.h, there is : #define M_PI 3.14159265358979323846
YZ>
YZ> So it should not generate this warning, but it did.
YZ>
YZ> How can I solve this issue?

You must be defining _USE_MATH_DEFINES somewhere (see the condition around
M_PI definition in <math.h>). Either don't do it at all, or do it before
including wx headers.

Regards,
VZ

--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/

Yili Zhao

unread,
Apr 2, 2015, 4:33:20 PM4/2/15
to wx-u...@googlegroups.com
Hi Vadim,
  You are right. There is a  "_USE_MATH_DEFINES" macro defined in one header file indeed. 
  I deleted its definition, and just include <wx/math.h>, and it is fine.
  Thanks!

在 2015年4月1日星期三 UTC+8下午8:12:16,Vadim Zeitlin写道:
Reply all
Reply to author
Forward
0 new messages