4 ms·
"If you compile C with libc statically linked in, it'll make executables as large as Rust's." $ cat test.c && musl-gcc -static -O2 test.c && echo && du -h
by mahkoh 7y ago
"If you compile C with libc statically linked in, it'll make executables as large as Rust's."
$ cat test.c && musl-gcc -static -O2 test.c && echo && du -h a.out
#include <stdio.h>
int main(void) {
printf("Hello World\n");
}
20K a.out
- pornel 7y agoI stand corrected. Congrats to MUSL!
- saagarjha 7y agoI would also imagine that the compiler is performing a couple of optimizations that would significantly reduce the resulting binary’s size: the call to printf would likely resolve to puts, which might be further optimized to a raw write call by a smart enough compiler.
- wbl 7y agoAnd possible dead code elimination in the linker.
- wdroz 7y agoWith an "old" gcc I use at work: echo $(gcc --version) && cat test.c && gcc -static -O2 test.c && echo && du -h a.out gcc (Debian 6.3.0-18+deb9u1) 6.3.0 20170516 ... #include <stdio.h> int main(void) { printf("Hello World\n"); } 796K a.out
- JohnFen 7y ago> If you compile C with libc statically linked in, it'll make executables as large as Rust's. Not in my experience.