I've searched for recent information on building compact Go executables, without success. Most information appears to be several years old.
My program: the standard hello world as found on Rosettacode.org. With Fortran I get an exe file under 100 KB. With Go the exe file is whopping 2400 KB.
My questions: are there compiler switches or pragmas that I should be using? Are there other tools or tricks I am not aware of (I am a beginner with Go). What are the future plans for Go regarding executable size? What is it like under Linux - same thing? What happens to exe files on large programs?
Background: I'm using go 1.5 installed on Windows 7. My project is writing (actually migrating from other languages) some command line programs. Having 20 or more large Go exe files eats up a lot of space. OK, I know space is cheap so I can live with it. However, I believe clarity on the matter will help many people.
A Go program is big because it contains garbage collaction code, goroutine scheduling code and besides that it has nearly all libraries statically linked. It is so by design.
To reduce the executable size, you can instruct the linker to strip debug symbols by using one of the following:
go install -ldflags '-s'
go install -ldflags '-s -w'
I tried it on a fairly large executable (one of the GXUI samples), and this reduced it from ~16M to ~10M. Adding -w to -s didn't make any difference, but as always, your mileage may vary...
Here is a full list of all linker options.