The size comes from statically linking to the standard library and runtime. To keep size down, you can pass `-C prefer-dynamic` to rustc to link to them dynamically instead.
On Mon, Feb 24, 2014 at 6:23 PM, S.A. <[email protected]> wrote: > Hello, > > I am new to rust and have a question on what options to pass to rustc > to reduce the size of the executable. I see a huge variation between the > exec generated from a simple C vs Rust program: > :::::::::::::: > hello1.rs > :::::::::::::: > fn main () { > println!("Hello World!"); > } > :::::::::::::: > hello2.rs > :::::::::::::: > use std::io::stdio; > > fn main () { > stdio::println("Hello World!"); > } > :::::::::::::: > hello.c > :::::::::::::: > #include <stdio.h> > main () { > printf ("Hello World!\n"); > } > > Compilations: > $ gcc -o hello_c hello.c > $ rustc hello1.rs > $ rustc hello2.rs > > Outputs from the above are: > -rwxrwxr-x 1 admin admin 8377 Feb 24 17:25 hello_c* > -rwxrwxr-x 1 admin admin 2874699 Feb 24 17:25 hello2* > -rwxrwxr-x 1 admin admin 2879032 Feb 24 17:25 hello1* > > As you can see the sizes of the rust execs (hello1 and hello2) are > far more than the simple C's. > > Set of linked libraries are: > $ ldd hello_c hello1 hello2 > hello_c: > linux-vdso.so.1 => (0x00007fff00bfe000) > libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f440cfc3000) > /lib64/ld-linux-x86-64.so.2 (0x00007f440d397000) > hello1: > linux-vdso.so.1 => (0x00007fff8effe000) > libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fbf2e1df000) > /lib64/ld-linux-x86-64.so.2 (0x00007fbf2e5b3000) > libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fbf2dfda000) > libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fbf2dcde000) > libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 > (0x00007fbf2dac1000) > libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 > (0x00007fbf2d8aa000) > librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fbf2d6a2000) > hello2: > linux-vdso.so.1 => (0x00007fffef7fe000) > libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 > (0x00007fc1853b2000) > librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fc1851a9000) > libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fc184de9000) > /lib64/ld-linux-x86-64.so.2 (0x00007fc1855e3000) > libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fc184be5000) > libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fc1848e8000) > libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 > (0x00007fc1846d2000) > > Can someone shed some light on this. > > Thanks > > > _______________________________________________ > 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
