Golang executable file size

I searched for the latest information on creating compact Go executables without success. Most of the information seems to be several years old.

My program: The standard hello world found on Rosettacode.org. With Fortran, I get an exe file under 100 KB. With Go, the EXE file has a whopping 2400KB.

My questions are: are there compiler switches or pragmas that I should use? Are there any other tools or tricks that I don't know about (I start with Go). What are Go's future plans for executable file size? What is it under Linux - the same thing? What happens to exe files on large programs?

Background: I am using go 1.5 installed on Windows 7. My project writes (actually transfers from other languages) some command-line programs. With 20 or more large Go exe files, you eat a lot of space. Well, I know that space is cheap, so I can live with it. However, I believe that clarity in this matter will help many people.

+4
source share
2 answers

A Go is great because it contains garbage collaboration code, goroutine scheduling code, and it also has almost all the libraries statically linked. This is so in design.

FAQ Why is my trivial program of such a large binary

+4
source

, :

go install -ldflags '-s'
go install -ldflags '-s -w'

( GXUI ), ~ 16M ~ 10M, -w -s , , , ...

- .

+2

Source: https://habr.com/ru/post/1607791/


All Articles