This error occurs when Rust can't find the Microsoft Visual C++ linker on Windows. Here are the minimal installation options to resolve it:
-
Download the Visual Studio Build Tools from Microsoft's official site:
- Go to https://visualstudio.microsoft.com/downloads/
- Scroll down to "Tools for Visual Studio"
- Download "Build Tools for Visual Studio"
-
Install with minimal components:
- Run the installer
- Select "C++ build tools" workload
- Under "Individual components", ensure these are checked:
MSVC v143 - VS 2022 C++ x64/x86 build tools
- For ARM64 systems: Also check
MSVC v143 - VS 2022 C++ ARM64 build tools
Windows 10/11 SDK
(latest version)- For ARM64 systems: Ensure you get the ARM64 version of the SDK
- Uncheck everything else to minimize install size
- Install size: ~2-3 GB (slightly larger with ARM64 tools)
-
Restart your terminal/command prompt after installation
If you prefer to avoid Visual Studio entirely:
-
Install the GNU toolchain target:
rustup target add x86_64-pc-windows-gnu
-
Install MinGW-w64:
- Download from https://www.mingw-w64.org/downloads/
- Or use a package manager like Chocolatey:
choco install mingw
-
Build using GNU target:
cargo build --target x86_64-pc-windows-gnu
-
Install the GNU toolchain target:
rustup target add aarch64-pc-windows-gnu
-
Install MinGW-w64 with ARM64 support:
- Use LLVM-MinGW which supports ARM64: https://github.com/mstorsjo/llvm-mingw
- Or use Chocolatey:
choco install llvm-mingw
-
Build using GNU target:
cargo build --target aarch64-pc-windows-gnu
- Native ARM64 compilation: If you're on ARM64 Windows and want to compile for ARM64, use the
aarch64-pc-windows-msvc
target (default) oraarch64-pc-windows-gnu
- Cross-compilation: You can still compile for x64 from ARM64 by adding the x64 target:
rustup target add x86_64-pc-windows-msvc
- Performance: Native ARM64 compilation will generally perform better than x64 emulation
After installation, verify the fix by running:
cargo build
The error should be resolved and your Rust project should compile successfully.
Note: Option 1 is recommended as it provides the best compatibility with Windows-specific crates and is the default toolchain Rust expects on Windows.