Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build failure - error C2065: 'M_PI': undeclared identifier` #49

Open
Dutchman101 opened this issue Jun 22, 2024 · 0 comments
Open

Build failure - error C2065: 'M_PI': undeclared identifier` #49

Dutchman101 opened this issue Jun 22, 2024 · 0 comments

Comments

@Dutchman101
Copy link

Due to build error (math library non-conformance), the project can't be built on certain platforms/IDE's. For this issue report i reproduced it using Visual Studio 2022 17.10.

The error:

speexdsp\libspeexdsp\testresample2.c(57,43): error C2065: 'M_PI': undeclared identifier

Happens here: libspeexdsp/testresample2.c Line 57

According to web sources, it is because 'M_PI' is not part of math.h or cmath in either C or C++, therefore i can imagine this out-of-the-box failure will appear for multiple environments.

Web sources suggest one of these solutions. I suggset speexdsp picks one for implementation.

Microsoft way (docs): "Math Constants are not defined in Standard C/C++. To use them, you must first define _USE_MATH_DEFINES and then include cmath or math.h BEFORE any other headers":

#define _USE_MATH_DEFINES
#include <cmath>
#incude other headers...

Different approaches, as you decide on portability and choice:

const double pi = 3.14159265358979323846;
#ifndef M_PI
    #define M_PI 3.14159265358979323846
#endif

GCC way:

#undef __STRICT_ANSI__
#include <cmath>

Compilers that support C++ 20 (use header numbers and constant pi), like so:

#include <numbers>
std::numbers::pi

cc @tmatth

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant