Rust MSVC builds fail on Windows: Git Bash link.exe shadows MSVC linker
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-msvctarget - 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
- Prepend MSVC tools directory to PATH — detect the MSVC toolchain via
vswhere.exeand prepend its bin directory - Set
CARGO_TARGET_X86_64_PC_WINDOWS_MSVC_LINKER— point at MSVC'slink.exeby full path - Use
rust-lld— ship a config that setslinker = "rust-lld"(bundled with Rust, avoids PATH conflict) - Document the workaround — at minimum, note the rename in Windows setup docs
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗