Linker errors

Fix Rust linker errors on Windows — LNK2019, LNK1181, link.exe not found

Rust linker errors on Windows (LNK2019, LNK1181, link.exe not found) are caused by missing MSVC Build Tools, incorrect feature flags in the windows crate, or a missing system library reference. The fix is almost always to install or repair Visual Studio Build Tools.

Fix "error: linker link.exe not found"

Error message
error: linker `link.exe` not found
| = note: program not found

This means the MSVC linker is not on PATH. Fix:

  • 1

    Install Visual Studio Build Tools 2022

    Download from visualstudio.microsoft.com. Select Desktop development with C++.

  • 2

    Reinstall the Rust toolchain

    PowerShell
    PS> rustup toolchain uninstall stable-x86_64-pc-windows-msvc
    PS> rustup toolchain install stable-x86_64-pc-windows-msvc

Fix "LNK2019: unresolved external symbol"

Error message
error LNK2019: unresolved external symbol __some_function referenced in function main

This means a function is declared but the library that implements it is not linked. Common fixes:

  • Add the missing feature flag to your windows crate dependency in Cargo.toml
  • Add a #[link(name = "library")] attribute or add to build.rs: println!("cargo:rustc-link-lib=library");
  • Ensure the Windows SDK is installed (check in Visual Studio Installer)

Fix "LNK1181: cannot open input file"

Error message
LINK: fatal error LNK1181: cannot open input file 'some.lib'

The linker cannot find a .lib file. This usually means:

  • The Windows SDK component providing that .lib is not installed
  • The library path is not in LIB environment variable
  • A build.rs script is referencing a library that does not exist on your system
Fix — check LIB path
# In Developer PowerShell for VS 2022:
PS> $env:LIB -split ";"
# Should list Windows SDK and MSVC lib paths

Linker error questions

Rust linker error after Visual Studio update

Visual Studio updates sometimes change the MSVC toolset version. Run rustup toolchain install stable to re-link rustup to the new MSVC version. If errors persist, open "Visual Studio Installer" and click Modify on Build Tools 2022 — verify the C++ components are still installed.

How to use GNU linker instead of MSVC on Windows?

Switch to the GNU toolchain: rustup default stable-x86_64-pc-windows-gnu. This requires MSYS2 with mingw-w64-x86_64-gcc. The GNU toolchain is less compatible with Windows-specific crates like windows-rs.