M_PI in VS2010: works in Debug conf, but not in Release

In my unmanaged C ++ source, I have:

#define _USE_MATH_DEFINES
#include <cmath>

and then I use M_PI a couple of times. Compilation in Debug configuration works flawlessly, but in Release it gives:

error C2065: "M_PI": undeclared identifier

What could be the configuration property causing this?

+5
source share
3 answers

solvable.

I put

#define _USE_MATH_DEFINES

before

#include "stdafx.h"

With Precompiled Headers on (/ Yu), as in Release mode, everything above it is ignored.

+6
source

The following code compiles for both debugging and release for me:

#define _USE_MATH_DEFINES
#include <cmath>

int main(void)
{
    double x = M_PI;
    return 0;
}

. ?

+3

Watch out for differences in Debug and Release configurations:

The most important thing:

  • include files
  • defines
+1
source

All Articles