3 ms·
Hello world in C++ is 1.3 MiB when linked statically. $ cat helloworld.cpp #include <iostream> int main() { std::cout << "Hello world" << st
by nly 12y ago
Hello world in C++ is 1.3 MiB when linked statically.
$ 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.out
- kevinnk 12y agoAs I've pointed out in a previous thread, virtually all of it is from a) iostreams and b) glibc. If you don't statically link glibc (as is the case the vast majority of the time) it's much smaller. Edit: You made my point for me in your edit :) Leaving my original comment for posterity.