Rust minimal compiled program size [duplicate]

2019-06-05 16:49发布

问题:

This question already has an answer here:

  • Why are Rust executables so huge? 5 answers
fn main() {
    println!("hello");
}

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?

回答1:

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