If this is the first time you are using Rust you will have to install Rust on your Windows machine.

To install see this link – https://www.rust-lang.org/tools/install

Check the version of Rust-

rustup --version

Check the version of Rsut compiler

rustc --version

Create a Rust project using Cargo

Cargo is a build and package manager.

For creating a new Rust project using Cargo package manager-

cargo new first_rust_prj

This should create follwoing folder structure with main.rs and Cargo.toml (configuration) file.

You can create a project without using Cargo. Create a src directory and create appropriate Cargo.toml namually. To create toml file use init command

cardo init

Building and Running Cargo project

Build the Cargo project using following command-

cargo build

To compile and run directly from the project folder, use following command-

cargo run

Error compiling the project-

error: linker link.exe not found

So the pre-requisite for windows machine is to have MS C++ build tools. Install the smae from here. It should be around 5 GB.

https://visualstudio.microsoft.com/visual-cpp-build-tools

Now this should run the project –

To check the code without producing an executable use follwoing command-

cargo check

Building for Release

Use following command when project is ready for release-

cargo build --release

References-

https://doc.rust-lang.org/book/ch01-01-installation.html#installing-rustup-on-linux-or-macos

Loading