How to build a release version binary in Go?

catric mia picture catric mia · Apr 13, 2015 · Viewed 31.8k times · Source

In C, we can build a debug version or a release version of the binary files (the object files and the executable). How can we do this in Go?

Answer

hiwjd0 picture hiwjd0 · Apr 13, 2015

In Go, it isn't typical to have a debug version or a release version.

By default, go build combines symbol and debug info with binary files. However, you can remove the symbol and debug info with go build -ldflags "-s -w".