Windows/MSVC: llama-server link fails with LNK2001 unresolved external "__" after #28091 (WINDOWS_EXPORT_ALL_SYMBOLS + PCH)
envgap__ggml-org__llama.cpp-28758
01 / FAILURE SIGNATURE
As reported upstream
exports.def : error LNK2001: unresolved external symbol "__"
Not a benchmark task.
- The project already builds and runs before the fix, so there is nothing to repair.
02 / ENVIRONMENT RECIPE
- Base commit
8172e6577ac2b35de1ec1e5d1c0aaad6c4a2129f- Manifest
tools/server/CMakeLists.txt- Reproduce
Awaiting issue-specific recipe- Run under trace
Awaiting a meaningful runtime command
03 / ORIGINAL ISSUE TEXT
ggml-org/llama.cpp #28758 · read the original issue
### Name and Version
`llama-server` fails to link on Windows/MSVC after #28091 (merged today). Tree at `5bda51b`, which is the first build of this repo I have made since `ca3d5a3` (Aug 28), so #28091 is the only PCH-related change in between.
```
> .\build\bin\llama-server.exe --version
version: 0.4.0-dev (build 254, commit 5bda51b)
built with MSVC 19.44.35228.0 for Windows AMD64
```
### Operating systems
Windows
### Which llama.cpp modules do you know to be affected?
llama-server
### Command line
```shell
cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DGGML_CUDA=ON -DCMAKE_CUDA_ARCHITECTURES=86-real -DLLAMA_CURL=OFF
cmake --build build --target llama-server -j 10
```
### Problem description & Steps to reproduce
Configure and build `llama-server` on Windows with MSVC. Everything compiles; the failure is at the link step of `llama-server-impl.dll`:
```
exports.def : warning LNK4022: no unique match for symbol "__"
exports.def : warning LNK4002: __@@_PchSym_@00@UooznzRnzhgviUyfrowUgllohUhvieviUxnzpvurovhUhvieviRxlmgvcgOwriUxnzpvPkxsOxccOlyq@4B2008FD98C1DD4
is defined in "tools\server\CMakeFiles\server-context.dir\cmake_pch.cxx.obj"
exports.def : warning LNK4002: __@@_PchSym_@00@UooznzRnzhgviUyfrowUgllohUhvieviUxnzpvurovhUooznzRhvieviRrnkoOwriUxnzpvPkxsOxccOlyq@4B2008FD98C1DD4
is defined in "tools\server\CMakeFiles\llama-server-impl.dir\cmake_pch.cxx.obj"
exports.def : error LNK2001: unresolved external symbol "__"
tools\server\llama-server-impl.lib : fatal error LNK1120: 1 unresolved externals
```
**Cause: `WINDOWS_EXPORT_ALL_SYMBOLS` and `target_precompile_headers` on the same target.**
`tools/server/CMakeLists.txt` sets both:
- line 35 / 53: `target_precompile_headers(${TARGET} PRIVATE ${CMAKE_SOURCE_DIR}/common/common.h)` (added by #28091)
- line 48: `set_target_properties(${TARGET} PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON)` (pre-existing)
`WINDOWS_EXPORT_ALL_SYMBOLS` makes CMake dump every symbol from every object file of the target into a generated `exports.def`. That now includes `cmake_pch.cxx.obj`, whose MSVC-internal `__@@_PchSym_@00@…` bookkeeping symbols have no linkable definition. The generated file here is 5672 lines and contains the PCH symbols alongside the real ones.
This is a known incompatibility between the two CMake features rather than anything specific to this repo — but the combination only became reachable here with #28091.
### Workaround
```shell
cmake -B build -DCMAKE_DISABLE_PRECOMPILE_HEADERS=ON
```
Costs the build-time win of #28091 on Windows but is otherwise free; the resulting binary is identical in behaviour (verified: same model, same flags, decode 18.5 vs 17.9 tok/s against the pre-#28091 build, i.e. the expected gain from the other commits in that range).
### Possible fix
Excluding the PCH object from the symbol dump would keep both features. Either skip PCH for the two targets that carry `WINDOWS_EXPORT_ALL_SYMBOLS`, or guard the `target_precompile_headers` calls in `tools/server/CMakeLists.txt` with something like
```cmake
if (NOT (WIN32 AND MSVC))
target_precompile_headers(${TARGET} PRIVATE ${CMAKE_SOURCE_DIR}/common/common.h)
endif()
```
I have not tested a patch for this, so I am filing it as a report rather than a PR — whichever shape you prefer, I am happy to verify it on this machine.
### Environment
RTX 3090, Windows 11 native (not WSL), MSVC toolset 14.44.35207 (cl 19.44.35228), CMake 4.3.2, Ninja, CUDA 13.1, `-DGGML_CUDA=ON -DCMAKE_CUDA_ARCHITECTURES=86-real`.
04 / LABELS
Labels from the report text only; not yet run
No supported category has been assigned.
Label rules and the text that matched
[]