构建 Go 程序以发布时,使用 `go build` 是标准做法吗?

huangapple go评论74阅读模式
英文:

When building Go programs for release is it standard practice to just use 'go build'?

问题

构建Go程序时,是否只使用go build而不使用其他选项是标准做法?我之所以问这个问题,是因为使用go build构建时,默认情况下会包含所有的调试信息。要删除这些信息,可以向链接器传递一个选项,如下所示:

go build -ldflags "-w" prog.go

这将省略所有的调试符号。在构建发布版本的程序时,您会删除这些信息还是保留它们?

编辑:为了明确起见,我想知道人们如何编译Go程序以部署到实际环境中。在其他编译语言中,针对调试和发布构建,您会有不同的编译器命令行选项,并且发布构建通常会对可执行文件进行优化并删除调试信息。

英文:

When building Go programs for release is it standard practise to just use go build without any other options? I ask because when building using go build all debug information is included by default. To remove it you can pass an option to the linker, thus:

go build -ldflags "-w" prog.go

This omits all debug symbols. When building programs for release do you remove this information or leave it intact?

EDIT: For clarity, i'm wondering how people compile Go programs for deployment to a live environment. In other compiled languages you have a different set of compiler command line options for debugging and release builds and release builds usually optimise the executable and remove debugging information.

答案1

得分: 3

根据Dave Cheney的说法,答案是肯定的,只需使用go build命令。

来源:http://www.reddit.com/r/golang/comments/2woogl/when_building_go_programs_for_release_is_it/

英文:

According to Dave Cheney the answer is yes, just use go build.

Source: http://www.reddit.com/r/golang/comments/2woogl/when_building_go_programs_for_release_is_it/

huangapple
  • 本文由 发表于 2015年2月22日 03:55:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/28650603.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定