Skip to content

cmake: fix MATH_LIBRARY check on Windows MSVC#22564

Open
ServeurpersoCom wants to merge 1 commit into
ggml-org:masterfrom
ServeurpersoCom:fix/mathlib-win-msvc
Open

cmake: fix MATH_LIBRARY check on Windows MSVC#22564
ServeurpersoCom wants to merge 1 commit into
ggml-org:masterfrom
ServeurpersoCom:fix/mathlib-win-msvc

Conversation

@ServeurpersoCom
Copy link
Copy Markdown
Contributor

@ServeurpersoCom ServeurpersoCom commented Apr 30, 2026

Overview

cmake : fix MATH_LIBRARY check on Windows MSVC

find_library(MATH_LIBRARY m) returns MATH_LIBRARY-NOTFOUND on MSVC, but if (DEFINED MATH_LIBRARY) is still TRUE, leading to target_link_libraries(... PRIVATE MATH_LIBRARY-NOTFOUND) and a 'cannot open m.lib' link error. Use idiomatic if (MATH_LIBRARY) which evaluates *-NOTFOUND as false.

This restores the truthy check that was in place before #22355; DEFINED is too permissive when MATH_LIBRARY is set elsewhere as *-NOTFOUND by an unrelated find_library() call earlier in configure.

Discovered while rebasing two GGML downstream projects

Refs #9908 (original old issue with the same Windows MSVC symptom)

Additional information

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: YES code browsing + english translator

@github-actions github-actions Bot added the ggml changes relating to the ggml tensor library for machine learning label Apr 30, 2026
@jeffbolznv
Copy link
Copy Markdown
Contributor

I had a similar error but it went away with a clean tree.

@ServeurpersoCom
Copy link
Copy Markdown
Contributor Author

I had a similar error but it went away with a clean tree.

You're right, if I delete the build folder it goes through, but doesn't the bug remain latent as soon as find_library(MATH_LIBRARY m) is called elsewhere in the configure step (downstream project, upstream submodule, or even a simple re-configure reloading the cache), since DEFINED still evaluates to TRUE with the value MATH_LIBRARY-NOTFOUND and breaks the link, whereas if (MATH_LIBRARY) correctly evaluates *-NOTFOUND as falsy per CMake's if() contract ?

@angt
Copy link
Copy Markdown
Member

angt commented May 1, 2026

We don’t want to call find_library(MATH_LIBRARY m) anymore as it has issues when building with GGML_STATIC=ON. The idea is to use an explicit -DMATH_LIBRARY=... when required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ggml changes relating to the ggml tensor library for machine learning

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants