-
Notifications
You must be signed in to change notification settings - Fork 46
Open
Description
Description
I encountered a build error when running make on a Linux environment. The compilation fails because the math constants M_PI and M_PI_2 are undeclared in tools/precalculator.c.
This usually happens when compiling with strict standard flags (e.g., -std=c99 or -ansi), as these constants are POSIX extensions and not part of the strict ISO C standard.
Error Log
tools/precalculator.c: In function ‘precalculate’:
tools/precalculator.c:44:35: error: ‘M_PI_2’ undeclared (first use in this function)
44 | float angle = i * (float) M_PI_2 / 256.0f;
| ^~~~~~
tools/precalculator.c:56:59: error: ‘M_PI’ undeclared (first use in this function)
56 | float s = 256.0f * sinf(i / 1024.0f * 2 * (float) M_PI);
| ^~~~
make: *** [Makefile:62: precalculator] Error 1
Proposed Fix
To resolve this while maintaining portability, we should define these constants if they are missing.
In tools/precalculator.c, adding the following block before the logic starts (or after the includes) resolves the issue:
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#ifndef M_PI_2
#define M_PI_2 1.57079632679489661923
#endifAlternatively, defining _GNU_SOURCE (for Linux) or _USE_MATH_DEFINES (for MSVC) before including <math.h> would also expose the library constants.
Environment
- OS: Linux (Ubuntu/Debian)
Metadata
Metadata
Assignees
Labels
No labels