• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

1.2rustcargo

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

cargo是rust的编译与打包工具,可将rust打包成为一个可执行性文件。生成的可执行性文件不能跨系统的大版本,比如在linux7上打包,那么程序无法在linux6上执行。

# cargo new hello_cargo
Created binary (application) `hello_cargo` package
# cd hello_cargo
# ls
Cargo.toml src
# ll -a
total 24
drwxr-xr-x 4 root root 4096 Jan 15 18:16 .
drwxr-xr-x 3 root root 4096 Jan 15 18:16 ..
-rw-r--r-- 1 root root  121 Jan 15 18:16 Cargo.toml
drwxr-xr-x 6 root root 4096 Jan 15 18:16 .git
-rw-r--r-- 1 root root   19 Jan 15 18:16 .gitignore
drwxr-xr-x 2 root root 4096 Jan 15 18:16 src
# cat Cargo.toml 
[package]
name = "hello_cargo"
version = "0.1.0"
authors = ["tanpf <[email protected]>"]
edition = "2018"

[dependencies]

 

# cd src
# ls
main.rs
# cat main.rs 
fn main() {
    println!("Hello, world!");
}
[root@itoracle src]# cargo build
   Compiling hello_cargo v0.1.0 (/usr/local/automng/src/rust/test/hello_cargo)                                                                                              
    Finished dev [unoptimized + debuginfo] target(s) in 3.05s                                                                                                               
[root@itoracle src]# ll
total 4
-rw-r--r-- 1 root root 45 Jan 15 18:16 main.rs
[root@itoracle hello_cargo]# ./target/debug/hello_cargo 
Hello, world!
[root@itoracle hello_cargo]# cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s                                                                                                               
     Running `target/debug/hello_cargo`
Hello, world!
[root@itoracle hello_cargo]# 
[root@itoracle hello_cargo]# 
[root@itoracle hello_cargo]# vim src/main.rs 

fn main() {
    println!("Hello, world!");
    println!("过年回家的火车票,为啥每次都抢不到呢");
}

如果修改了代码,cargo run会先编译再运行

[root@itoracle hello_cargo]# cargo run
   Compiling hello_cargo v0.1.0 (/usr/local/automng/src/rust/test/hello_cargo)                                                                                              
    Finished dev [unoptimized + debuginfo] target(s) in 0.46s                                                                                                               
     Running `target/debug/hello_cargo`
Hello, world!
过年回家的火车票,为啥每次都抢不到呢

cargo check进行代码的编译,但不生成可执行文件,速度比cargo build快很多,当代码比较多时,可以先check

[root@itoracle hello_cargo]# cargo check
    Checking hello_cargo v0.1.0 (/usr/local/automng/src/rust/test/hello_cargo)                                                                                              
    Finished dev [unoptimized + debuginfo] target(s) in 0.13s 

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
MATLAB数学建模发布时间:2022-07-18
下一篇:
【转】Modules in Rust发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap