Rust 最小编译程序大小 [英] Rust minimal compiled program size
本文介绍了Rust 最小编译程序大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
fn main() {
println!("hello");
}
此程序编译 600 毫秒,生成的二进制文件大小为 600KB.这是为什么?我只是在尝试 Rust,并将其与 C 进行比较.C 编译类似程序的速度会快 10 倍,而二进制输出会小 100 倍.那是为什么?
This program compiles 600 ms and the resulting binary is 600KB in size. Why is that? I am just trying Rust, and comparing it to C. C would compile similar program 10 times faster and the binary output will be 100 times smaller. So why is that?
推荐答案
可执行文件的大小主要是因为 Rust 的标准库默认是静态链接的.尝试使用 rustc -O -C prefer-dynamic
编译,你应该得到一个与 C 版本相当的二进制文件.
The executable size is mostly because rust's standard library is statically linked in by default. Try compiling with rustc -O -C prefer-dynamic
and you should get a binary that's comparable to the C version.
这篇关于Rust 最小编译程序大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文