2020-05-08 13:40:54 +01:00
|
|
|
# go build
|
|
|
|
|
2020-05-11 04:49:49 +01:00
|
|
|
> Compile Go sources.
|
|
|
|
> More information: <https://golang.org/cmd/go/#hdr-Compile_packages_and_dependencies>.
|
2020-05-08 13:40:54 +01:00
|
|
|
|
2022-01-02 04:30:56 +00:00
|
|
|
- Compile a 'package main' file (output will be the filename without extension):
|
2020-05-08 13:40:54 +01:00
|
|
|
|
2020-05-14 17:01:50 +01:00
|
|
|
`go build {{path/to/main.go}}`
|
2020-05-08 13:40:54 +01:00
|
|
|
|
2020-05-14 17:01:50 +01:00
|
|
|
- Compile, specifying the output filename:
|
2020-05-08 13:40:54 +01:00
|
|
|
|
2020-05-14 17:01:50 +01:00
|
|
|
`go build -o {{path/to/binary}} {{path/to/source.go}}`
|
2020-05-11 04:49:49 +01:00
|
|
|
|
|
|
|
- Compile a package:
|
|
|
|
|
2020-05-14 17:01:50 +01:00
|
|
|
`go build -o {{path/to/binary}} {{path/to/package}}`
|
2020-05-11 04:49:49 +01:00
|
|
|
|
2022-01-02 04:30:56 +00:00
|
|
|
- Compile a main package into an executable, enabling data race detection:
|
2020-05-11 04:49:49 +01:00
|
|
|
|
2020-05-14 17:01:50 +01:00
|
|
|
`go build -race -o {{path/to/executable}} {{path/to/main/package}}`
|