Windows builds of XNNPACK work well, but the toolchain setup trips people up more often than on Linux, mostly because of generator mismatches between Visual Studio and CMake. This guide covers a setup that avoids the most common issues.
Prerequisites
- Visual Studio 2019 or later, with the "Desktop development with C++" workload installed
- CMake 3.x, either standalone or the copy bundled with Visual Studio
- Ninja (optional but recommended — it builds noticeably faster than the default MSBuild generator)
- Python 3, needed for XNNPACK's build-time kernel code generation scripts
- Git, if you're cloning rather than downloading a ZIP archive
Choosing a generator
You have two realistic options: the native Visual Studio generator, or Ninja running inside a Developer Command Prompt. Ninja is faster and avoids some quirks with long build-file names, so it's the generator used in the example below.
Open a Developer Command Prompt
Launch "x64 Native Tools Command Prompt for VS" from the Start menu rather than a plain Command Prompt or PowerShell window — this sets up the MSVC environment variables that CMake and Ninja both rely on.
Configure and build
cd path\to\XNNPACK
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release
cmake --build build --config Release
Common Windows-specific issues
"Ninja not found"
Ninja isn't bundled with every Visual Studio install. Install it separately and make sure its folder is on your PATH, or point CMake at it explicitly with -DCMAKE_MAKE_PROGRAM.
Path length errors
Deeply nested build paths can hit Windows' historical path-length limits. Building from a short root path like C:\dev\xnnpack instead of a long nested folder avoids this entirely.
Mixing 32-bit and 64-bit toolchains
Make sure the command prompt you opened matches the architecture you intend to build for. Mixing an x86 Developer Command Prompt with an x64 target (or vice versa) produces confusing linker errors.
Where to go next
If your build configures but fails partway through compilation, our build troubleshooting guide covers the most common failure points across platforms.