Is it packaging a lot of extras that aren't needed for such a simple program?
Is it packaging a lot of extras that aren't needed for such a simple program?
$ cat helloworld.cpp
#include <iostream>
int main() {
std::cout << "Hello world" << std::endl;
}
$ g++ -std=c++14 -Os -static helloworld.cpp
$ size a.out
text data bss dec hex filename
1294232 29692 92936 1416860 159e9c a.out
The majority of this is bloat from GNU libc though, using diet libc would yield better results $ cat helloworld.c
#include <stdio.h>
int main() {
puts ("Hello world");
}
$ gcc -std=c99 -Os -static helloworld.c
$ size a.out
text data bss dec hex filename
725706 7572 9080 742358 b53d6 a.outEdit: You made my point for me in your edit :) Leaving my original comment for posterity.
Yes, a simple "Hello World" winds up statically linking a fairly sizeable standard library, in particular anything dealing with strings has to involve a certain amount of UTF-8 manipulation and the formatting and I/O have a lot of features and thus likely fairly large code size. But for the most part that's just fixed overhead, and you can opt out of using the standard library if you want and produce smaller executables.
If you want tiny binaries using dynamic linking then you can use "rustc -C prefer-dynamic".
I'm happy it does static linking by default because like you said hard drives are cheap and it's safer.