跳转到主要内容

安装rust

安装

# windows:

https://static.rust-lang.org/rustup/dist/x86_64-pc-windows-msvc/rustup-init.exe

根据提示,安装msvc和windows sdk


# linux:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

# 安装完成后需要刷新环境变量
source "$HOME/.cargo/env"


安装完成后,使用 rustc --version 验证安装成功

编写hello,world

# vi main.rs

fn main() {
    println!("Hello, world!");
}

# 使用rustc编译源文件
rustc main.rs

使用cargo构建和包管理器



# 显示管理版本
cargo --version

# 创建一个新项目
cargo new hello_cargo

# 编译,编译debug版本
cargo build

# 编译,编译release版本
cargo build --release

# 编译并运行
cargo run

# 编译检查
 cargo check