Cargo 是 Rust 的构建系统和包管理器,使用 Cargo 来管理 Rust 项目,因为它可以为你处理很多任务,比如构建代码、下载依赖库并编译这些库。
cargo安装
#安装rust(自带cargo)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
#检查cargo是否安装成功
cargo --version
cargo构建helloword
1.创建helloword项目
#生成hello_cargo目录、main.rs源码、Cargo.toml配置
cargo new hello_cargo
2.构建并运行项目
#进入目录
cd hello_cargo
#编译项目,target/debug目录生成可执行文件
cargo build
#执行编译生成可执行程序
./target/debug/hello_cargo
cargo命令
#创建项目
cargo new myproject
#构建项目(默认debug版本)
cargo bulid
#构建项目(release版本)
cargo build --release
#构建项目并运行
cargo run
#快速检查项目代码que确保可编译
cargo check