Fix Windows build failure caused by extern "C" wrapper in oci.cpp #48
+880
−101
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
The Windows build fails when compiling
common/oci.cppwith the error:This occurs because
oci.cppwraps the include ofliboci.hin anextern "C"block:Root Cause
The
liboci.hfile is generated by cgo and already provides its ownextern "C"block for C function declarations. On Windows with MSVC, this generated header conditionally includes<complex>which contains C++ standard library templates:When these C++ templates are pulled in through the outer
extern "C"block inoci.cpp, the compiler correctly rejects them since templates cannot have C linkage.Solution
Remove the unnecessary
extern "C"wrapper fromoci.cpp. The cgo-generatedliboci.halready provides the correct linkage specifications for its exported functions at lines 86-94:This change also applies proper code formatting to the file according to the project's
.clang-formatrules (IndentPPDirectives: AfterHash).Testing
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.