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

@ServeurpersoCom ServeurpersoCom commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

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

angt commented May 1, 2026

Copy link
Copy Markdown
Member

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.

@ggerganov

Copy link
Copy Markdown
Member

@ServeurpersoCom Is this change still needed or did the clean tree resolve the problem that you had?

@ServeurpersoCom

Copy link
Copy Markdown
Contributor Author

Deleting the "build" folder resolves the issue.
Either it's a genuine MSVC bug, in which case we discard this PR, or it provides robustness to prevent encountering the bug, and we can keep it.

@TimexPeachtree TimexPeachtree left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Great this made it possible for me to build it. After update gave issues.

@ServeurpersoCom

Copy link
Copy Markdown
Contributor Author

The workaround is to delete the build dir, but this fix actually corrects the underlying problem.

@TimexPeachtree

TimexPeachtree commented May 22, 2026

Copy link
Copy Markdown

The workaround is to delete the build dir, but this fix actually corrects the underlying problem.

I mean i followed this 'cmake clean' command and didn't delete the build folder. It worked only after applying your fix.

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.

5 participants