[Rust] Configure the Rust+VS Code development environment on Windows and Linux

This article introduces the configuration of Rust+VS Code development environment on Windows and Linux.

Windows

Install

In fact, installing Rust on Linux is easy by comparison. The process for Windows is tedious.

Download the rust installation package from this website: Rust

The installation process will be performed by terminal printing. Rust currently does not have a graphical installation process on Windows.

Rust needs to install two things, one is rustup and the other is cargo. These two will be installed on the C drive by default. If you do not want Rust to be installed on the C drive, you need to set the environment variable in advance.

  1. By RUSTUP_HOMEspecifying the directory where rustup is installed.
    rustup

  2. By CARGO_HOMEspecifying the directory where cargo is installed.
    cargo
    Ready to install.
    Install
    Rust requires a computer with a C++ compiler, and it is recommended to use the default MSVC under Windows. If you want to change to GNU, you need to choose Customize installation. Of course, I don't recommend changing to GNU, because there will be many inexplicable bugs.

After installation, enter the following command in the terminal to verify that Rust is installed successfully:

rustc -V

rust
Verify that cargo is installed successfully:

cargo -V

cargo

Configure VS Code

First install this extension: rust-analyzer

Create new rust project:

cargo new HelloWorld

Open the folder with VS Code
vscode
and click "Run" to compile and run the rust project
run

Linux(Ubuntu 20.04 LTS)

I don't have a dual system, so I will use WSL as an example to demonstrate the Rust installation.

Install

Just two lines of command:

sudo apt install rustc
sudo apt install cargo

Of course, the environment needs gcc, you can check it

gcc -v

Configure VS Code

same order

cargo new HelloRust

Switch and open with VS Code.
wsl vscode
I don’t know why, but the rust-analyzer plugin under WSL doesn’t work properly.
report error

So I can only use the terminal to execute the command instead, and I will look for the reason later:

cargo run

Results of the

Guess you like

Origin blog.csdn.net/qq_37387199/article/details/127590483