Hacker News new | ask | show | jobs
by nerdponx 3166 days ago
2.17 MB is still enormous for a "hello world" binary.
2 comments

No. 2.17 MB is NOT enormous. Usually there is no runtime library. In contrast, C or C++ runtime libraries can easily exceed that size. For example, vc_redist.x64.exe is 13.9 MB.
It's a matter of platform and the libraries that you're using.

After all, back in the days we had 360k floppy disks, and executable written in C which did much more than just printing out "Hello world" would fit comfortably into less than half of that.

Modern C and C++ runtimes are bloated, because a 2MB executable isn't considered huge anymore and dynamic linking is common.

But you can have a 5k static executable printing "hello world" on Linux if you just trade in your stdlibc to musl. People have also managed to use musl with Rust to produce pretty small executables: https://lifthrasiir.github.io/rustlog/why-is-a-rust-executab...

(Note: The size in the article is 21.7 MB, and not 2.17 MB!)

I just tried building a statically linked 'hello world' c++ program, and co-incidentally, the binary also happened to be 2.1 MB!

   #include <iostream>
   
   int main( int, const char *[] )
   {
      std::cout << "Hello World!" << std::endl;
      return 0;
   }

'g++ -static -o hello hello.cpp' produces a binary of 2191112 bytes (Linux x64). Stripping it of debug symbols leaves a 1.7 MB file.
Go runtime is included in the executable. C or C++ do not automatically do that when writing a simple "hello world" and compiling it into an executable. stdio isn't statically linked by default.

And when rid of debugging symbols, even when importing the fmt package :

    package main

    import "fmt"

    func main() {
        fmt.Print("Hello World")
    }
go build -ldflags "-s -w" hello.go

is 1.3MB .