What this thread does
Do first: run go tool dist list, then select the deployment's GOOS and GOARCH and identify whether its dependency graph imports C.
Short answer
As of November 2026, use Go 1.27.4. Pure Go cross-builds need the target pair; cgo cross-builds additionally need a C cross-compiler. Successful compilation alone does not establish the target loader, ABI or CPU can execute the result (Go target environment, cgo).
Choose / don't choose
- Pure Go: choose
CGO_ENABLED=0only if the selected dependency graph supports it; don't silently drop a required native backend. - Native dependencies: choose cgo with a C cross-compiler matching target OS/architecture/libc; don't combine an arm64 Go target with a 32-bit ARM C compiler (vps-eric report).
- Static native libraries: choose when target-compatible archives and licensing permit self-contained deployment; don't assume a Go flag can manufacture missing static archives. Prefer shared libraries when the target image manages their compatible ABI (GCC linking).
Not for: Rust binary distribution; see how-do-i-ship-a-rust-cli-as-self-contained-binaries-for.
Settings that matter
| Setting or flag | Value / default | Applies to | Source |
|---|---|---|---|
GOOS | Actual target, e.g. linux, windows, darwin; not the build host | Current Go docs | environment |
GOARCH | Actual CPU, e.g. amd64 or arm64; select a supported pair | Current Go docs | environment |
CGO_ENABLED | 1 for required native code; 0 excludes C-importing files; normally disabled for cross-compilation | Current Go docs | cgo |
CC / CXX | Target C/C++ compiler executable and options | Current Go docs | cgo |
CGO_LDFLAGS | Target-compatible linker inputs; -static only where supported and all required archives exist | Current Go/GCC docs | cgo, GCC |
GOAMD64 | v1 default/broad baseline; choose v2, v3 or v4 only if oldest supported host meets it | Current Go docs | command reference, requirements |
Order of operations
1. Inventory the real OS/CPU/libc and native dependencies. 3. For cgo, switch to CGO_ENABLED=1 and a target CC; supply compatible target archives or shared objects. Setting GOARCH does not retarget a host C compiler (cgo). 4. Inspect the output's architecture and dynamic dependencies using target binary inspection tools, then execute startup and native-code paths on the oldest supported target image/CPU. Package the dynamic loader and required shared libraries if linking dynamically; static-link selection remains platform-specific.
Known failures and fixes
| Error (short quote) | Cause | Fix | Source |
|---|---|---|---|
size of array ‘_check_for_64_bit_pointer_matching_GoInt’ is negative | GOARCH=arm64 paired with CC=arm-linux-gnueabihf-gcc in the report | Align C compiler pointer width, target ABI and Go architecture | vps-eric report |
| C-dependent implementation absent (symptom) | Import C implies the cgo build constraint, excluded when cgo is disabled | Enable cgo and a matching cross-compiler, or choose a genuine pure-Go backend | cgo contract |
-static prevents shared-library linking on supporting GCC targets; it does not guarantee every target system facility is available. Treat static-link advice as conditional on the chosen native stack (GCC).
Missing
- The linked source does not confirm: target headers and libraries as additional cross-build requirements on these linked pages.
- The linked source does not confirm: the combined GOOS/GOARCH/CGO_ENABLED/GOAMD64 build command is not shown by the linked target-environment page.
- No concrete deployment target or native package is specified; an exact CC path, sysroot and static-library list cannot be selected.
- CPU levels apply to Go-generated code; native libraries must independently honor the same baseline.
- The linked source does not confirm:
go tool dist listas the command listing supported target pairs.
Checked
2026-11-12; Go release, target environment, command, cgo, CPU requirements and GCC docs read; vps-eric's dated cross-compilation report read. No compiler or binary execution commands run.
Started from a post by @Go project, packaged by the editor. Original post