Skip to content

Conversation

Copy link

Copilot AI commented Oct 19, 2025

Problem

The Windows build fails when compiling common/oci.cpp with the error:

error: templates must have C++ linkage

This occurs because oci.cpp wraps the include of liboci.h in an extern "C" block:

extern "C" {
#include "../oci-go/liboci.h"
}

Root Cause

The liboci.h file is generated by cgo and already provides its own extern "C" block for C function declarations. On Windows with MSVC, this generated header conditionally includes <complex> which contains C++ standard library templates:

#ifdef _MSC_VER
#if !defined(__cplusplus) || _MSVC_LANG <= 201402L
#include <complex.h>
typedef _Fcomplex GoComplex64;
#else
#include <complex>  // C++ header with templates
typedef std::complex<float> GoComplex64;
#endif
#endif

When these C++ templates are pulled in through the outer extern "C" block in oci.cpp, the compiler correctly rejects them since templates cannot have C linkage.

Solution

Remove the unnecessary extern "C" wrapper from oci.cpp. The cgo-generated liboci.h already provides the correct linkage specifications for its exported functions at lines 86-94:

#ifdef __cplusplus
extern "C" {
#endif

extern char* PullOCIModel(char* imageRef, char* cacheDir);
extern void FreeString(char* s);

#ifdef __cplusplus
}
#endif

This change also applies proper code formatting to the file according to the project's .clang-format rules (IndentPPDirectives: AfterHash).

Testing

  • ✅ Builds successfully on Linux (CPU backend)
  • ✅ No security vulnerabilities introduced
  • ✅ Code review completed

The fix should resolve the Windows build failure while maintaining compatibility with all platforms.

Original prompt

Fix windows build, it fails with:

[98/253] Building CXX object common/CMakeFiles/common.dir/Release/oci.cpp.obj
FAILED: [code=1] common/CMakeFiles/common.dir/Release/oci.cpp.obj
ccache C:\PROGRA~1\LLVM\bin\CLANG_~1.EXE -DGGML_USE_CPU -DGGML_USE_RPC -DLLAMA_USE_CURL -DLLAMA_USE_OCI -D_CRT_SECURE_NO_WARNINGS -DCMAKE_INTDIR="Release" -ID:/a/llama.cpp/llama.cpp/oci-go -ID:/a/_temp/libcurl/include -ID:/a/llama.cpp/llama.cpp/common/. -ID:/a/llama.cpp/llama.cpp/common/../vendor -ID:/a/llama.cpp/llama.cpp/src/../include -ID:/a/llama.cpp/llama.cpp/ggml/src/../include -O3 -DNDEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrt -std=gnu++17 -Wmissing-declarations -Wmissing-noreturn -Wall -Wextra -Wpedantic -Wcast-qual -Wno-unused-function -Wunreachable-code-break -Wunreachable-code-return -Wmissing-prototypes -Wextra-semi -MD -MT common/CMakeFiles/common.dir/Release/oci.cpp.obj -MF common\CMakeFiles\common.dir\Release\oci.cpp.obj.d -o common/CMakeFiles/common.dir/Release/oci.cpp.obj -c D:/a/llama.cpp/llama.cpp/common/oci.cpp
In file included from D:/a/llama.cpp/llama.cpp/common/oci.cpp:11:
In file included from cgo-gcc-export-header-prolog:19:
In file included from C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt\complex.h:15:
In file included from C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.44.35207\include\ccomplex:11:
In file included from C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.44.35207\include\complex:13:
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.44.35207\include\sstream:21:13: error: templates must have C++ linkage
21 | _EXPORT_STD template <class _Elem, class _Traits, class _Alloc>
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
D:/a/llama.cpp/llama.cpp/common/oci.cpp:10:1: note: extern "C" language linkage specification begins here
10 | extern "C" {
| ^
In file included from D:/a/llama.cpp/llama.cpp/common/oci.cpp:11:
In file included from cgo-gcc-export-header-prolog:19:
In file included from C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt\complex.h:15:
In file included from C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.44.35207\include\ccomplex:11:
In file included from C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.44.35207\include\complex:13:
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.44.35207\include\sstream:605:13: error: templates must have C++ linkage
605 | _EXPORT_STD template <class _Elem, class _Traits, class _Alloc>
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
D:/a/llama.cpp/llama.cpp/common/oci.cpp:10:1: note: extern "C" language linkage specification begins here
10 | extern "C" {
| ^
In file included from D:/a/llama.cpp/llama.cpp/common/oci.cpp:11:
In file included from cgo-gcc-export-header-prolog:19:
In file included from C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt\complex.h:15:
In file included from C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.44.35207\include\ccomplex:11:
In file included from C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.44.35207\include\complex:13:
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.44.35207\include\sstream:611:13: error: templates must have C++ linkage
611 | _EXPORT_STD template <class _Elem, class _Traits, class _Alloc>
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
D:/a/llama.cpp/llama.cpp/common/oci.cpp:10:1: note: extern "C" language linkage specification begins here
10 | extern "C" {
| ^
In file included from D:/a/llama.cpp/llama.cpp/common/oci.cpp:11:
In file included from cgo-gcc-export-header-prolog:19:
In file included from C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt\complex.h:15:
In file included from C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.44.35207\include\ccomplex:11:
In file included from C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.44.35207\include\complex:13:
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.44.35207\include\sstream:724:13: error: templates must have C++ linkage
724 | _EXPORT_STD template <class _Elem, class _Traits, class _Alloc>
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
D:/a/llama.cpp/llama.cpp/common/oci.cpp:10:1: note: extern "C" language linkage specification begins here
10 | extern "C" {
| ^
In file included from D:/a/llama.cpp/llama.cpp/common/oci.cpp:11:
In file included from cgo-gcc-export-header-prolog:19:
In file included from C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt\complex.h:15:
In file included from C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.44.35207\include\ccomplex:11:
In file included fr...


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

ericcurtin and others added 2 commits October 19, 2025 21:18
So we can pull from any OCI registry, add authentication, etc.

Add docker-style progress bars and resumable downloads to OCI pulls

Update documentation with progress bars and resumable downloads info

Make OCI Go build optional and skip editorconfig for oci-go

Add Go version check before building OCI library

Signed-off-by: Eric Curtin <[email protected]>
Copilot AI and others added 2 commits October 19, 2025 20:38
This is a generated file that should not have been modified in the previous commit.
Copilot AI changed the title [WIP] Fix windows build failure during compilation Fix Windows build failure caused by extern "C" wrapper in oci.cpp Oct 19, 2025
Copilot AI requested a review from ericcurtin October 19, 2025 20:43
Copilot finished work on behalf of ericcurtin October 19, 2025 20:43
@ericcurtin ericcurtin force-pushed the integrate-go-containerregistry-library branch from e4b192d to 2935963 Compare October 19, 2025 20:47
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