Go go build 命令

Go About 461 words

查看帮助

go help build

-p n

多核CPU并行编译构建。

-race

开启竞态检测。

-compile name

指定编译器gccgogc。默认gc

-tags

指定标签。

ldflags参数

命令:

go build -v -ldflags "-X main.Version=1.0 -X main.BuildTime=date -X 'main.GoVersion=`go version`'"

代码:

var (
    Version   string
    BuildTime string
    GoVersion string
)

func main() {
    fmt.Printf("%s\n%s\n%s\n", Version, BuildTime, GoVersion)
}

-w

禁止生成DWARF。二进制文件将不能使用gdbdlv调试。

-s

禁用符号表。异常时堆栈信息将没有文件名/代码行号等信息。

-X

设置代码中的变量值

更多参数

go tool link
Views: 3,434 · Posted: 2020-11-05

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh