Skip to content

cmake: refined conditions for math library linking on windows - #11312

Closed
Xarbirus wants to merge 1 commit into
ggml-org:masterfrom
Xarbirus:math-lib-for-windows-builds
Closed

cmake: refined conditions for math library linking on windows#11312
Xarbirus wants to merge 1 commit into
ggml-org:masterfrom
Xarbirus:math-lib-for-windows-builds

Conversation

@Xarbirus

@Xarbirus Xarbirus commented Jan 20, 2025

Copy link
Copy Markdown
Contributor

I encountered some problems when building llama.cpp on windows (for x64 and arm64) on a system where MSVC (with clang) and mingw are installed at the same time.

It seems to me that the condition for adding MATH_LIBRARY to the build is not quite correct. MATH_LIBRARY should not be added if

  • Intel oneAPI is already used (since these libraries include optimized math libraries and tools)
  • or the MSVC compiler is used

An important addition - in case clang is used in the MSVC pipeline, we should not add the library (condition CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC" was added for this). At the same time, when building with mingw, the library can be added.

I think this would also be a solution to this issue (if it hadn't closed).

@github-actions github-actions Bot added the ggml changes relating to the ggml tensor library for machine learning label Jan 20, 2025
@slaren

slaren commented Jan 28, 2025

Copy link
Copy Markdown
Member

I encountered some problems when building llama.cpp on windows (for x64 and arm64) on a system where MSVC (with clang) and mingw are installed at the same time.

Can you suggest a way to reproduce the issue that you are seeing? Does it happen with a specific version of mingw? I have mingw installed alongside MSVC, and the github runners do as well, so at least it doesn't happen in every case.

@Xarbirus

Copy link
Copy Markdown
Contributor Author

Hi @slaren in my case, the problem occurs when 3 compilers are installed on the system at once: msvc, mingw and clang.
I use vcvarsall.bat to set environment variables, and compile the project with the clang compiler.
The problem looks like this:

[51/134] Linking CXX executable bin\Release\llama-gguf.exe
FAILED: bin/Release/llama-gguf.exe
cmd.exe /C "cd . && C:\PROGRA~1\LLVM\bin\CLANG_~1.EXE --target=x86_64-pc-windows-msvc -fuse-ld=lld-link -nostartfiles -nostdlib -fms-compatibility  -fvectorize -ffp-model=fast -fno-finite-math-only -Wno-format -Wno-unused-variable -Wno-unused-function -Wno-gnu-zero-variadic-macro-arguments -O3 -DNDEBUG -fms-runtime-lib=static -Xlinker /subsystem:console examples/gguf/CMakeFiles/llama-gguf.dir/Release/gguf.cpp.obj -o bin\Release\llama-gguf.exe -Xlinker /implib:examples\gguf\Release\llama-gguf.lib -Xlinker /pdb:bin\Release\llama-gguf.pdb -Xlinker /version:0.0   ggml/src/Release/ggml.lib  ggml/src/Release/ggml-cpu.lib  ggml/src/Release/ggml-base.lib  -lm.lib  -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 -loldnames && cd ."
lld-link: error: could not open 'm.lib': no such file or directory

In my understanding the problem occurs because cmake finds libraries related to mingw (m.lib) because the path to mingw is in the path environment variable.

@Xarbirus

Xarbirus commented May 5, 2025

Copy link
Copy Markdown
Contributor Author

Hi @slaren! I would like to clarify if there are any plans to merge this pr?

@slaren

slaren commented May 5, 2025

Copy link
Copy Markdown
Member

I was not able to reproduce the issue that you mentioned. I have all 3 compilers installed, and so does the github CI. I am not comfortable merging something that I don't understand.

@Xarbirus

Xarbirus commented May 7, 2025

Copy link
Copy Markdown
Contributor Author

Okay, thanks, I'll try to dig deeper into our CI.

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.

2 participants