Introduction: Your first "Hello, world!" in Rust that won't work
\n\nYou just installed Rust, opened a terminal, wrote your first code in this elegant and safe language, typed cargo run — and immediately got a confusing red line:
error: linker `link.exe` not found\n |\n = note: The system cannot find the file specified. (os error 2)\n\n\nSound familiar? Don't panic! You've encountered one of the most popular problems among beginners switching to Rust on Windows. This error is not a compiler bug or a curse. It's simply a misunderstanding between your new friend Rust and the operating system. Thousands of developers have gone through this on Stack Overflow, and today we'll sort this out once and for all. Welcome to the world of system programming on Windows — here you need a little more than just installing the language.
\n\nWhy doesn't Rust see link.exe? Understanding the root of the problem
\n\nTo understand why the linker link.exe not found error occurs, you need to look under the hood of the compilation process. When you write rustc main.rs or cargo build, Rust compiles your code into object files. But that's not the end. To get a ready executable file (.exe), these object files need to be linked together. This work is done by a special program — the linker.
On Windows, the default linker is link.exe from the Microsoft Visual C++ (MSVC) toolset. Rust, being a language that "friends" with the system compiler, chooses the MSVC toolchain by default (if you didn't specify otherwise during installation). The problem is that this linker is not part of Windows. It comes with Visual Studio or a separate Build Tools for Visual Studio package.
Key point: Rust cannot find link.exe because it is simply not installed on your computer, or not added to the system environment variable PATH.
Quick checklist: what could have gone wrong?
\n- \n
- You installed Rust via
rustup-init.exeand pressed "Enter" everywhere. This is normal, but the installer does not install Visual Studio. \n - You have Visual Studio Code or another IDE installed, but not Visual Studio. These are not the same thing. \n
- You chose the
GNUtoolchain during installation. If so, you need not MSVC, butGCC(e.g., via MinGW). But today we're talking about the standard MSVC. \n
Solution #1: Install Visual Studio Build Tools (Recommended method)
\n\nThis is the most correct and "native" way for Windows. Microsoft offers a free package that includes only the compiler and linker — without the bulky IDE.
\n\n- \n
- Download the installer: Go to the official Microsoft website and download Build Tools for Visual Studio 2022. Search for "Visual Studio 2022 Build Tools". \n
- Run the installation: Launch the downloaded
vs_BuildTools.exe. \n - Select components: In the installer, select the "Workloads" tab. Check the box for "Desktop development with C++". \n
- Install: Click the "Install" button in the lower right corner. The process may take 10-20 minutes, as about 2-3 GB of data is downloaded. \n
- Restart (optional): After installation completes, restart your computer so that the environment variables are updated. \n
After that, open a new terminal and try compiling your project again:
\n\ncargo new hello_world