GOOS and GOARCH
The two Go settings that choose the target operating system and processor family a build produces a binary for.
In more detail
Examples are GOOS=linux, darwin or windows and GOARCH=amd64 or arm64. Setting them before go build is all cross compilation takes for pure Go code. Inside a running program, runtime.GOOS and runtime.GOARCH report the pair the binary was built for.
Example
GOOS=linux GOARCH=arm64 go build -o probe .Related terms
- cross compilation — Building a program on one kind of machine for a different operating system or processor, such as a Linux binary on a Mac.
- CPU architecture — The family of instructions a processor understands, such as 64-bit Intel (amd64) or 64-bit Arm (arm64).
- operating system — The base software, such as Linux, Windows or macOS, that runs a computer and lets other programs use it.
- go env — The go subcommand that prints the settings the toolchain is using, such as GOPATH, GOOS and GOARCH.
Taught in
- Building Static Binaries — Concurrent Systems Programming with Go
- Containerizing and Testing the Final Build — Concurrent Systems Programming with Go