Installing Rust on Windows 10 (native)

This is a quick how to for Windows 10 2004.

  1. Download and run rustup.rs
  2. Download Build Tools for Visual Studio 2019 hidden under "Tools for Visual Studio 2019"
  3. Run "Build Tools for Visual Studio 2019 Installer" and select
    • C++ Tools
  4. While in the C++ Tools you have to select "Windows 10 SDK" as well. There will be multiple options, go with the highest version number.

Testing the installation

  1. Open a new PowerShell or "Command Prompt" and type the following commands. Each one must return without error.
  2. Go to the temporary directory: cd %TEMP%
  3. Create a new test project: cargo new toolchain_test
  4. Enter the newly created directory: cd toolchain_test
  5. Build and run the "Hello, world!" program: cargo run

Now you should see some compiling and then Hello, world!

Possible errors

The tools/compiler just stopped working

Under Windows you have to keep track of which environment you are using.

  • Command Prompt / cmd and PowerShell are the native Windows environment. It is the same as when you start a program from the start menu.
  • Windows Subsystem for Linux (WSL) or WSL 2 are mostly isolated POSIX environments running on top of Windows. Applications installed inside a WSL might not be visible from outside.
  • MINGW64 is similar to WSL 1. It is an overlay installation designed to run Linux programs on Windows. It is sometimes installed my other software like git.

You can use rustup inside the encapsulated environments too. However, then the programs created depend on their environment. So you would have to cross-compile them for stable-x86_64-pc-windows-msvc the native Windows environment.

cl.exe exits with error code 2 or "stdlib.h" not found:

You are probably missing the "Windows 10 SDK".

  1. Restart the "Build Tools for Visual Studio 2019 Installer"
  2. In the tile "Visual Studio Build Tools 2019" press "Modify"
  3. Under C++ Tools enable the "Windows 10 SDK", which at the time of writing is 10.0.18362.0.

Add Windows 10 SDK

cargo command not found

You are probably missing cargo in your %PATH%.

  • First, Open a new and fresh shell and try there. The %PATH% variable is only loaded when the terminal starts.
  • If that did not work, you can execute rustup.exe again and re-install the rust toolchain
  • Or you can edit the PATH variable by hand in the computers settings.

links

social