rust货架代码_Rust <0>:源代码组织,Cargo 入门

Rust 源代码组织,使用配套的 Cargo 工具,其功能强大,程序员可摆脱 C/C++ 中需要自行维护 make、cmake 之类配置的工作量。

初始化一个项目:

cargo new --bin hello_world

指定 --bin 选项代表创建的是一个直接可执行的二进制项目,否则会生成一个库项目。

执行 cargo run && cargo run --release 之后,项目目录结构如下:

zsh/3 114 (git)-[master]-%tree

.

├── Cargo.lock

├── Cargo.toml

├── src

│   └── main.rs

└── target

├── debug

│   ├── build

│   ├── deps

│   │   └── hello_world-f745b285e01df5ca

│   ├── examples

│   ├── hello_world

│   ├── hello_world.d

│   ├── incremental

│   └── native

└── release

├── build

├── deps

│   └── hello_world-7399f171987fdf9d

├── examples

├── hello_world

├── hello_world.d

├── incremental

└── native

生成的二进制文件位于项目路径下的 target/debug 或 target/release 子目录中,--release 指生成编译优化版的二进制文件,类似于 C 语言开启 -O2 优化选项。

其中 Cargo.toml 是 Cargo 用来管理项目结构的配置文件,其初始内容如下:

zsh/3 116 (git)-[master]-% catCargo.toml

[package]

name= "hello_world"version= "0.1.0"authors= ["kt "]

[dependencies]

____

注:rust 生成的最终可执行文件,都是无外部依赖的静态编译结果。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值