nikoss nikoss - 1 year ago 81
C Question

Go binary size in comparison with c

Yesterday I just wanted to compare simple golang

app with c, go binary was something like
2-3 MB
) the equivalent c code, however, was just about 20 kb (
). Then I checked system calls both binaries were doing, using
; there was not a huge difference between both so do you have any idea why golang binary is so massive in comparison with c equivalent?

Answer Source

Go binaries are, by default, statically linked, and also contain more information such as information about types that allows for reflection, type assertions, and so on. To quote the Go FAQ:

The linker in the gc tool chain creates statically-linked binaries by default. All Go binaries therefore include the Go run-time, along with the run-time type information necessary to support dynamic type checks, reflection, and even panic-time stack traces.

A simple C "hello, world" program compiled and linked statically using gcc on Linux is around 750 kB, including an implementation of printf. An equivalent Go program using fmt.Printf is around 2.3 MB, but that includes more powerful run-time support and type information.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download