美文网首页
Rust环境搭建

Rust环境搭建

作者: 和谐共处 | 来源:发表于2021-01-06 11:29 被阅读0次

安装Rust

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

#检查是否安装成功
$ rustc --version
rustc 1.50.0-nightly (b48cafd9e 2020-11-25)
#检查Rust 的构建工具和包管理器
$ cargo --version
cargo 1.50.0-nightly (bfca1cd22 2020-11-24)

创建项目

#简单点
$ mkdir hello_rust
$ cd hello_rust
$ touch main.rs

#使用cargo,会自动生成main.rs以及相应包管理文件Cargo.toml
$ cargo new hello_rust

编辑main.rs

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

编译或运行rust源码

#第-种适合单个无依赖的rust文件
$ cd hello_rust
$ rustc main.rs
$ ./main
#第二种推荐适用于cargo创建的项目如:cargo new hello_rust
$ cd hello_rust
$ cargo build
$ cargo run

相关文章

网友评论

      本文标题:Rust环境搭建

      本文链接:https://www.haomeiwen.com/subject/xdjnoktx.html