tldr/pages.zh/common/go-build.md

21 lines
582 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# go build
> 编译 Go 源代码。
> 更多信息:<https://golang.org/cmd/go/#hdr-Compile_packages_and_dependencies>.
- 编译 package main 文件(输出为不带扩展名的文件名):
`go build {{路径/到/main.go}}`
- 编译并指定输出文件名:
`go build -o {{路径/到/二进制文件}} {{路径/到/源文件.go}}`
- 编译一个包:
`go build -o {{路径/到/二进制文件}} {{路径/到/包}}`
- 编译 main 包为可执行文件,并开启数据竞态检测:
`go build -race -o {{路径/到/可执行文件}} {{路径/到/main/包}}`