How to build a release version binary in Go?

China☆狼群 提交于 2019-12-20 11:01:38

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!