Rust minimal compiled program size [duplicate]

2019-06-05 16:31发布

This question already has an answer here:

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?

标签: rust
1条回答
乱世女痞
2楼-- · 2019-06-05 16:43

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.

查看更多
登录 后发表回答