Compiled file size

Hi,

I’m new on Go and tried the “hello world” source code on the install page.

package main

import "fmt"

func main() {
    fmt.Printf("hello, world\n")
}
```
Wich after compiling the code it results in a 1.5 MB(!) executable (go 1.8/CentOS 7). Nearly the same code in C will only generate a few KB.

What makes this difference? Can I reduce it by including the right libs?

Greetings,
Maik

Hi!

This is, literally, a FAQ: https://golang.org/doc/faq#Why_is_my_trivial_program_such_a_large_binary

In short, your Go program includes stuff not included in the C compiled equivalent, and depends less on it’s external environment. This, by the way, is awesome.

3 Likes

Ok, thx. I should read the FAQ first…

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.