Hi, Adrian,
Currently Rust uses static linking to build executables. This means that the
simplest «hello world» program utilizing standard library will take all of this
library and all dependent libraries, including Rust runtime, into itself.
That’s why the binary is large.
If you want to use dynamic linking, you can invoke rustc with `-C
prefer-dynamic` arguments, this will link the program dynamically, and it will
be much smaller (8 KB in my case):
% cat main.rs
fn main() {
println!("Hello world")
}
% rustc -C prefer-dynamic main.rs
% ls -lh main
-rwxr-xr-x 1 dpx-infinity dpx-infinity 8,0K июл 11 12:14 main
However, this will mean that the binary is no longer portable; you can’t
compile it yourself and distribute it to other machines unless these machines
also have the same version of Rust installed.
Disk size is cheap these days, and portability really do matter, so that’s why
the static linkage is default. BTW, Go does exactly the same thing.
On 11 июля 2014 г., at 12:07, Adrian Mercieca <[email protected]> wrote:
> Hi all,
>
> I am just starting out looking at Rust and am following the tutorial.
>
> I have compiled the sample 'hello world' program (code below - copied from
> the tutorial) and compiled it.
>
> I was somewhat taken aback at the size of the executable size for such a
> small program.
>
> On my Ubuntu 13.10 machine, the resultant executable was a whopping 1054476
> bytes.
> I stripped the program and the resultant file was still 806816 bytes.
>
> Why is the executable so large? Is there anything I might be doing wrong?
> Perhaps I need to use some compiler switches?
>
> Thanks for any pointers in this regard.
>
> - Adrian.
>
> _______________________________________________
> Rust-dev mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/rust-dev
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev