News for hackers. Stuff that matters.
Re:Using Java 9 Modularization to Ship Zero-Dependency Nativ... by nerdponx on Sunday October 22, 2017 @09:12PM (#15530001)
2.17 MB is still enormous for a "hello world" binary.
Re:Using Java 9 Modularization to Ship Zero-Dependency Nativ... by c_shu on Sunday October 22, 2017 @09:22PM (#15530025)
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.
Re:Using Java 9 Modularization to Ship Zero-Dependency Nativ... by unscaled on Sunday October 22, 2017 @10:12PM (#15530198)
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...

Re:Using Java 9 Modularization to Ship Zero-Dependency Nativ... by joosters on Sunday October 22, 2017 @09:43PM (#15530110)
(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.
Re:Using Java 9 Modularization to Ship Zero-Dependency Nativ... by taspeotis on Monday October 23, 2017 @12:03AM (#15530629)
Re:Using Java 9 Modularization to Ship Zero-Dependency Nativ... by camus2 on Sunday October 22, 2017 @09:42PM (#15530096)
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 .