Rust MSVC builds fail on Windows: Git Bash link.exe shadows MSVC linker

Resolved 💬 2 comments Opened Feb 6, 2026 by ajaykagrawal Closed Mar 6, 2026

Summary

cargo build (and even bare rustc) fails for any Rust project targeting x86_64-pc-windows-msvc when invoked from Claude Code on Windows. Claude Code runs under Git Bash (MSYS2), which ships /usr/bin/link.exe — a POSIX hard-link utility — that shadows MSVC's link.exe on PATH.

Since rustc searches PATH for link.exe to invoke the linker, it finds the wrong one and every link step fails.

Reproduction

From Claude Code on Windows with the MSVC Rust toolchain, compile anything:

echo 'fn main(){}' > test.rs && rustc test.rs

Error

error: linking with `link.exe` failed: exit code: 1
  = note: "C:\Program Files\Git\usr\bin\link.exe" "/NOLOGO" ...
  = note: /usr/bin/link: extra operand '...'

Environment

  • Windows 10/11
  • Git for Windows (any version — ships MSYS2 coreutils including /usr/bin/link.exe)
  • Rust stable, x86_64-pc-windows-msvc target
  • Claude Code running under Git Bash / MSYS2

Impact

This affects all Rust MSVC development from Claude Code on Windows. Even a trivial fn main(){} fails to link.

Workaround

Rename the POSIX link utility (requires elevated prompt):

rename "C:\Program Files\Git\usr\bin\link.exe" link-posix.exe

The POSIX link command is almost never used (ln is the standard tool).

Possible fixes

  1. Prepend MSVC tools directory to PATH — detect the MSVC toolchain via vswhere.exe and prepend its bin directory
  2. Set CARGO_TARGET_X86_64_PC_WINDOWS_MSVC_LINKER — point at MSVC's link.exe by full path
  3. Use rust-lld — ship a config that sets linker = "rust-lld" (bundled with Rust, avoids PATH conflict)
  4. Document the workaround — at minimum, note the rename in Windows setup docs

View original on GitHub ↗

This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗