简体   繁体   中英

Why does the Rust compiler generate huge executables?

Compiling a simple hello world application like this:

fn main() {
    println!("Hello, World!");
}

Generates a relatively huge 822 KB executable using the default compiler options ( rustc hello.rs ).

Why does this happen and what is the best way to reduce the size of the executable?

  1. The standard library is linked statically by default. You can change that by passing the -C prefer-dynamic option to the compiler.

  2. Rust is still a very young language with an incompletely optimized compiler. There is still a lot of room left for improvements in compilation speed, code speed and size, wording of error messages and so on.

rustc -C opt-level=2 hello.rs给出4kb二进制

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM