We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 5252

Summary: Build warning on MSVC: M_PI redefined
Product: SDL Reporter: Albert Vaca Cintora <albertvaka>
Component: buildAssignee: Sam Lantinga <slouken>
Status: ASSIGNED --- QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 Keywords: target-2.0.16
Version: 2.0.12   
Hardware: All   
OS: Windows 10   

Description Albert Vaca Cintora 2020-08-09 18:26:27 UTC
On MSVC, including SDL.h and later including math.h, produces:

warning C4005: 'M_PI': macro redefinition

This is because SDL defines its own M_PI constant and math.h tries to define it again.

Instead of defining our own M_PI in SDL_stdinc.h, we should include math.h instead.

Note that, on top of that, MSVC needs _USE_MATH_DEFINES to be defined before including math.h, otherwise it won't define M_PI.
Comment 1 Albert Vaca Cintora 2020-08-10 23:22:19 UTC
I found this problem is quite more easy to reproduce than I thought. If _USE_MATH_DEFINES is set, just by including SDL.h we trigger the compiler warning in MSVC about M_PI being redefined.

This is due to the following include chain:

SDL.h -> SDL_main.h -> SDL_stdinc.h -> #define M_PI
SDL.h -> SDL_thread.h -> process.h -> corecrt_startup.h -> math.h -> #define M_PI again (if _USE_MATH_DEFINES is set)

I think SDL should not define M_PI itself and instead include math.h
Comment 2 Albert Vaca Cintora 2020-08-23 16:35:52 UTC
It seems this fork of SDL has a similar fix to what I'm proposing here, so at least one more person found this annoying: https://github.com/Jimbly/SDL/commit/2e42806dbca55a22b5b15a4a5becc779f2118735