Unable to compile Rust hello world on Windows: linker link.exe not found
Error Overview
When attempting to compile a simple Rust program, such as “hello world,” on a Windows machine, you may encounter the error message: “Unable to compile Rust hello world on Windows: linker link.exe not found.” This issue typically arises due to a missing or improperly configured linker, which is essential for transforming your Rust code into an executable binary.
Common Causes
The error can be attributed to several common causes:
- Missing Linker: The linker (link.exe) is not installed on your system or is not accessible in the system PATH.
- Incorrect Toolchain: You may be using the wrong Rust toolchain. Rust has multiple toolchains, including those for Windows with the GNU toolchain and the Microsoft Visual C++ (MSVC) toolchain.
- Visual Studio Build Tools: If you are using the MSVC toolchain, the necessary Visual Studio Build Tools may not be installed.
- Configuration Issues: The Rust toolchain might not be properly set up or configured on your machine.
- Outdated Rust Installation: An outdated installation of Rust could result in compatibility issues with the linker.
Solution Methods
To resolve the “Unable to compile Rust hello world on Windows: linker link.exe not found” error, follow these methods:
Method 1: Install the Correct Toolchain
-
Open the Command Prompt: Press
Win + R, typecmd, and hitEnter. -
Install the GNU Toolchain: Run the following command to install the stable GNU toolchain:
bash
rustup toolchain install stable-x86_64-pc-windows-gnu -
Set the Default Toolchain: Execute the command to set the GNU toolchain as the default:
bash
rustup default stable-x86_64-pc-windows-gnu -
Build Your Project: Navigate to your Rust project directory and run:
bash
cargo build - Compile Successfully: A successful compilation should indicate that your project has been compiled without errors.
Method 2: Use Visual Studio Build Tools
-
Uninstall Previous Toolchain: If you have the MSVC toolchain installed, uninstall it using:
bash
rustup uninstall toolchain stable-x86_64-pc-windows-msvc - Install C++ Build Tools: Download and install the Visual Studio Build Tools from Microsoft’s website.
- Reinstall the GNU Toolchain: Repeat the installation of the GNU toolchain as in Method 1.
-
Set the Default Toolchain: Again, set the GNU toolchain as the default using the command:
bash
rustup default stable-x86_64-pc-windows-gnu -
Verify Installation: You can verify the installation by running:
bash
cargo run
Method 3: Ensure Proper Configuration
- Check Environment Variables: Ensure that the path to the Visual Studio Build Tools (if using MSVC) or the GNU toolchain is included in your system’s PATH environment variable.
-
Update Rust: If you suspect your installation is outdated, update Rust with the following command:
bash
rustup update -
Rebuild Your Project: Navigate to your project directory and run:
bash
cargo build -
Test with a Simple Program: Create a simple Rust file (e.g.,
main.rs) with the following content:
“`rust
fn main()

コメント