Skip to content

fix: define M_PI for MSVC builds#18

Merged
mudler merged 1 commit into
mudler:masterfrom
mvanhorn:fix/6-msvc-m-pi-undefined
Jun 7, 2026
Merged

fix: define M_PI for MSVC builds#18
mudler merged 1 commit into
mudler:masterfrom
mvanhorn:fix/6-msvc-m-pi-undefined

Conversation

@mvanhorn

@mvanhorn mvanhorn commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

Problem

On MSVC, M_PI is not declared by <cmath> unless _USE_MATH_DEFINES is defined before the header is included, so the build fails with identifier "M_PI" is undefined (#6). The constant is used in src/fft.cpp, src/mel_gpu.cpp, and the test sources.

Fix

  • In src/fft.cpp and src/mel_gpu.cpp, define _USE_MATH_DEFINES before <cmath> and add an #ifndef M_PI fallback, so the library sources compile regardless of toolchain or include ordering.
  • In CMakeLists.txt, add _USE_MATH_DEFINES for MSVC as a PUBLIC compile definition on the parakeet target. PUBLIC (rather than PRIVATE) propagates it to consumers that link the library, so the test executables built with -DPARAKEET_BUILD_TESTS=ON (test_fft, test_audio_io, test_mel_gpu, which also use M_PI) get the define as well.

Non-MSVC builds are unaffected: the generator expression only emits the define for CXX_COMPILER_ID:MSVC, and the #ifndef guards are no-ops where M_PI is already provided.

Testing

  • Constant/define-only change; no runtime logic is modified.
  • Verified the generator expression is scoped to MSVC and that the PUBLIC definition reaches the test targets through target_link_libraries(<test> PRIVATE parakeet).

Closes #6

AI was used for assistance.

M_PI is not declared by <cmath> on MSVC unless _USE_MATH_DEFINES is set
before the header. Define it (plus an #ifndef M_PI fallback) in fft.cpp and
mel_gpu.cpp, and add _USE_MATH_DEFINES as a PUBLIC MSVC compile definition on
the parakeet target so the test executables that also use M_PI build too.
Non-MSVC builds are unaffected.

Closes mudler#6

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@mudler mudler left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, thanks

@mudler mudler merged commit eb09678 into mudler:master Jun 7, 2026
@mvanhorn

Copy link
Copy Markdown
Contributor Author

Thanks @mudler for landing this. M_PI defined for MSVC means Windows builds work out of the box.

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

Successfully merging this pull request may close these issues.

Identifier "M_PI" is undefined

2 participants