【Rust】可执行文件

环境

  • Rust 1.56.1
  • VSCode 1.61.2

概念

参考:https://doc.rust-lang.org/stable/rust-by-example/cargo/conventions.html

示例

默认情况下,生成的可执行文件和 cargo 中定义的一样,下面的方式可以生成多个可执行文件。

项目结构

foo
├── Cargo.toml
└── src
    ├── main.rs
    └── bin
        └── other.rs

Cargo.toml

[package]
name = "rust"
version = "0.1.0"
edition = "2021"

[dependencies]

main.rs

fn main() {
    println!("main.rs")
}

other.rs

fn main() {
    println!("other.rs")
}

默认可执行文件

PS C:\Users\jiangbo\work\workspace\rust\rust> cargo run --bin rust
   Compiling rust v0.1.0 (C:\Users\jiangbo\work\workspace\rust\rust)
    Finished dev [unoptimized + debuginfo] target(s) in 1.74s
     Running `target\debug\rust.exe`
main.rs

其它可执行文件

PS C:\Users\jiangbo\work\workspace\rust\rust> cargo run --bin other
   Compiling rust v0.1.0 (C:\Users\jiangbo\work\workspace\rust\rust)
    Finished dev [unoptimized + debuginfo] target(s) in 1.82s
     Running `target\debug\other.exe`
other.rs

总结

了解了 Rust 中怎么可以生成多个可执行文件,以及怎么运行。

附录

posted @   jiangbo4444  阅读(638)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示