I recently switched from Linux to Windows 11 and installed Rust. Cargo commands work fine, but when I try to build a project I get this error:
error: linker `link.exe` not found
|
= note: program not found
note: the msvc targets depend on the msvc linker but `link.exe` was not found
note: please ensure that Visual Studio 2017 or later, or Build Tools for Visual Studio were installed with the Visual C++ option.
I installed Visual Studio 2022 and Build Tools 2022 with the C++ workload, but Rust still can’t find link.exe. I even tried using WSL (Ubuntu) and installing the MSVC target there, but it still fails.
I couldn’t locate link.exe to set a path manually. How can I correctly compile Rust for the x86_64 MSVC target on Windows 11?
I had this same issue when I installed Rust on Windows 11. I'm not totally sure why it happens, but I think has something to do with the MSVC linker not being found. I also had the Build Tools for Visual Studio installed, but it still didn't work. If you don't specifically need the MSVC toolchain, you can use the windows-gnu toolchain:
you can run cargo from the "visual studio developer prompt".
did you install rustup before or after visual C++ build tools? normally, when you install rustup, it should be able to find the visual C++ tools from the registry.
since you already have the C++ tools installed, you can try to uninstall then reinstall rustup.
I also use the way. All executable' become bulky after, for example 5MB instead of 800KB on Linux. However a disk space cheap now, and I do not need extra tools.