问题
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?
回答1:
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"
.
回答2:
You can instruct the linker to strip debug symbols by using
go install -ldflags '-s'
I just tried it on a fairly large executable (one of the GXUI samples), and this reduced it from ~16M to ~10M. As always, your mileage may vary...
Here is a full list of all linker options.
来源:https://stackoverflow.com/questions/29599209/how-to-build-a-release-version-binary-in-go