4 ms·
A statically linked hello world in C using the MS toolchain gives me a 77Kb binary. The C++ version, using std::cout, is 176Kb.
by PowerGuido87 10y ago
A statically linked hello world in C using the MS toolchain gives me a 77Kb binary. The C++ version, using std::cout, is 176Kb.
- steveklabnik 10y agoIt's not clear (though it seems like no?) that the parent used options like LTO that would reduce the binary size.
- brainspider 10y agoI just literally installed the compiler toolset and did the first demo in the tutorial. I have never seen anything so large before, but I'm not a coder and not a windows coder. The only windows code I have compiled has been FreePascal and that wasn't this crazy. Similar to what sebcat showed above, I've done a bit of assembly on systems 8bit and up including nasm on linux, so not used to binaries with this sort of baggage. Wasn't trying to paint rust in a negative light, just came as a surprise when I ran that first compile.
- steveklabnik 10y agoIt's all good! I'm not assuming any malice. First impressions are also very important.
- sebcat 10y ago5344 byte statically linked hello world in C: $ musl-gcc -static -Os -s -o hello hello.c $ ls -la hello -rwxrwxr-x. 1 sebastian sebastian 5344 Sep 30 06:22 hello $ ldd hello not a dynamic executable $ ./hello Hello, World 384 Byte hello world using NASM and ld on linux/amd64: BITS 64 global _start %define SYS_write 1 %define SYS_exit 60 %define STDOUT_FILENO 1 section .text _start: call after strHello: db 'Hello, World!',10 lenHello equ $-strHello after: pop rsi mov rdx, lenHello mov rax, SYS_write mov rdi, STDOUT_FILENO syscall mov rax, SYS_exit xor rdi, rdi syscall Most of the size overhead in the latter example comes from the ELF header, so by paying a bit more attention to the linker scripts, or just inlining a small ELF header with db in the asm file, it would be even smaller. Just for size comparison. I am sure that it's quite possible to generate small Rust binaries as well.
- kibwen 10y ago> I am sure that it's quite possible to generate small Rust > binaries as well. Indeed, here's a 151-byte hello world[0] in Rust: http://mainisusuallyafunction.blogspot.com/2015/01/151-byte-static-linux-binary-in-rust.html http://mainisusuallyafunction.blogspot.com/2015/01/151-byte-...