Skip to content

Conversation

Copy link

Copilot AI commented Oct 19, 2025

Problem

The build fails on Windows ARM64 when using clang with OCI support enabled:

FAILED: common/CMakeFiles/common.dir/Release/oci.cpp.obj
In file included from D:/a/llama.cpp/llama.cpp/common/oci.cpp:10:
cgo-gcc-export-header-prolog:20:9: error: unknown type name '_Fcomplex'; did you mean '_complex'?
   20 | typedef _Fcomplex GoComplex64;

The issue occurs because the Go CGO-generated header file liboci.h uses MSVC-specific complex number types (_Fcomplex and _Dcomplex) when _MSC_VER is defined. While clang on Windows defines _MSC_VER for compatibility, it doesn't support these MSVC-specific types.

Solution

This PR adds a post-processing step to patch the generated liboci.h header file after Go builds it. The patch modifies the conditional compilation logic to detect __clang__ and use C++ standard std::complex types instead of MSVC-specific types when compiling with clang.

Changes:

  1. common/CMakeLists.txt: Added commands to run the patch script after Go generates the header
  2. common/patch_liboci_header.cmake: New CMake script that performs the header patching

The patch changes the header logic from:

#ifdef _MSC_VER
#if !defined(__cplusplus) || _MSVC_LANG <= 201402L
    typedef _Fcomplex GoComplex64;    // Not supported by clang
    typedef _Dcomplex GoComplex128;

To:

#ifdef _MSC_VER
#if defined(__clang__) || (defined(__cplusplus) && _MSVC_LANG > 201402L)
    typedef std::complex<float> GoComplex64;     // Clang-compatible
    typedef std::complex<double> GoComplex128;

This ensures clang uses C++ standard complex types that it supports, while maintaining compatibility with native MSVC compilation.

Testing

  • ✅ Verified the patch correctly modifies the Windows-generated header
  • ✅ Confirmed build succeeds on Linux with OCI support enabled
  • ✅ No security vulnerabilities introduced

Fixes the build error reported in the Windows ARM64 clang CI environment.

Original prompt

Fix this build:

[146/295] Linking CXX shared library bin\Release\llama.dll
clang++: warning: argument unused during compilation: '-fno-finite-math-only' [-Wunused-command-line-argument]
[147/295] Building CXX object examples/simple-chat/CMakeFiles/llama-simple-chat.dir/Release/simple-chat.cpp.obj
D:/a/llama.cpp/llama.cpp/examples/simple-chat/simple-chat.cpp:170:37: warning: 'strdup' is deprecated: The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _strdup. See online help for details. [-Wdeprecated-declarations]
170 | messages.push_back({"user", strdup(user.c_str())});
| ^
C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt\string.h:531:20: note: 'strdup' has been explicitly marked deprecated here
531 | Check_return _CRT_NONSTDC_DEPRECATE(_strdup)
| ^
C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt\corecrt.h:428:50: note: expanded from macro '_CRT_NONSTDC_DEPRECATE'
428 | #define _CRT_NONSTDC_DEPRECATE(_NewName) _CRT_DEPRECATE_TEXT(
| ^
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.44.35207\include\vcruntime.h:358:47: note: expanded from macro '_CRT_DEPRECATE_TEXT'
358 | #define _CRT_DEPRECATE_TEXT(_Text) __declspec(deprecated(_Text))
| ^
D:/a/llama.cpp/llama.cpp/examples/simple-chat/simple-chat.cpp:190:42: warning: 'strdup' is deprecated: The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _strdup. See online help for details. [-Wdeprecated-declarations]
190 | messages.push_back({"assistant", strdup(response.c_str())});
| ^
C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt\string.h:531:20: note: 'strdup' has been explicitly marked deprecated here
531 | Check_return _CRT_NONSTDC_DEPRECATE(_strdup)
| ^
C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt\corecrt.h:428:50: note: expanded from macro '_CRT_NONSTDC_DEPRECATE'
428 | #define _CRT_NONSTDC_DEPRECATE(_NewName) _CRT_DEPRECATE_TEXT(
| ^
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.44.35207\include\vcruntime.h:358:47: note: expanded from macro '_CRT_DEPRECATE_TEXT'
358 | #define _CRT_DEPRECATE_TEXT(_Text) __declspec(deprecated(_Text))
| ^
2 warnings generated.
[148/295] Linking CXX executable bin\Release\llama-gguf-hash.exe
clang++: warning: argument unused during compilation: '-fno-finite-math-only' [-Wunused-command-line-argument]
[149/295] Linking CXX shared library bin\Release\mtmd.dll
clang++: warning: argument unused during compilation: '-fno-finite-math-only' [-Wunused-command-line-argument]
[150/295] Linking C executable bin\Release\test-c.exe
clang: warning: argument unused during compilation: '-fno-finite-math-only' [-Wunused-command-line-argument]
[151/295] Linking CXX executable bin\Release\llama-simple.exe
clang++: warning: argument unused during compilation: '-fno-finite-math-only' [-Wunused-command-line-argument]
[152/295] Linking CXX executable bin\Release\llama-simple-chat.exe
clang++: warning: argument unused during compilation: '-fno-finite-math-only' [-Wunused-command-line-argument]
[153/295] Linking CXX executable bin\Release\llama-gguf.exe
clang++: warning: argument unused during compilation: '-fno-finite-math-only' [-Wunused-command-line-argument]
[154/295] Building OCI Go library
go: downloading github.com/google/go-containerregistry v0.20.6
go: downloading golang.org/x/term v0.36.0
go: downloading github.com/docker/cli v28.2.2+incompatible
go: downloading github.com/opencontainers/go-digest v1.0.0
go: downloading github.com/mitchellh/go-homedir v1.1.0
go: downloading golang.org/x/sync v0.15.0
go: downloading golang.org/x/sys v0.37.0
go: downloading github.com/docker/distribution v2.8.3+incompatible
go: downloading github.com/pkg/errors v0.9.1
go: downloading github.com/sirupsen/logrus v1.9.3
go: downloading github.com/opencontainers/image-spec v1.1.1
go: downloading github.com/containerd/stargz-snapshotter/estargz v0.16.3
go: downloading github.com/klauspost/compress v1.18.0
go: downloading github.com/docker/docker-credential-helpers v0.9.3
go: downloading github.com/vbatts/tar-split v0.12.1
[155/295] Building CXX object common/CMakeFiles/common.dir/Release/chat-parser.cpp.obj
[156/295] Building CXX object common/CMakeFiles/common.dir/Release/common.cpp.obj
[157/295] Building CXX object common/CMakeFiles/common.dir/Release/console.cpp.obj
[158/295] Building CXX object common/CMakeFiles/common.dir/Release/json-partial.cpp.obj
[159/295] Building CXX object common/CMakeFiles/common.dir/Release/llguidance...


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Fix build issues and deprecated uses in simple-chat Fix OCI build failure on Windows ARM64 with clang Oct 19, 2025
Copilot AI requested a review from ericcurtin October 19, 2025 21:19
Copilot finished work on behalf of ericcurtin October 19, 2025 21:19
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.

2 participants