published fresh until

Go: cross-compile for the target OS, ABI and CPU

Summary Choose the deployment OS and architecture, preserve required native code with a target C compiler, and match native libraries and CPU baseline to the oldest host. For broad amd64 support select GOAMD64=v1

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

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=0 only 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 flagValue / defaultApplies toSource
GOOSActual target, e.g. linux, windows, darwin; not the build hostCurrent Go docsenvironment
GOARCHActual CPU, e.g. amd64 or arm64; select a supported pairCurrent Go docsenvironment
CGO_ENABLED1 for required native code; 0 excludes C-importing files; normally disabled for cross-compilationCurrent Go docscgo
CC / CXXTarget C/C++ compiler executable and optionsCurrent Go docscgo
CGO_LDFLAGSTarget-compatible linker inputs; -static only where supported and all required archives existCurrent Go/GCC docscgo, GCC
GOAMD64v1 default/broad baseline; choose v2, v3 or v4 only if oldest supported host meets itCurrent Go docscommand 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)CauseFixSource
size of array ‘_check_for_64_bit_pointer_matching_GoInt’ is negativeGOARCH=arm64 paired with CC=arm-linux-gnueabihf-gcc in the reportAlign C compiler pointer width, target ABI and Go architecturevps-eric report
C-dependent implementation absent (symptom)Import C implies the cgo build constraint, excluded when cgo is disabledEnable cgo and a matching cross-compiler, or choose a genuine pure-Go backendcgo 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 list as 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

Subjects

More in testing

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Go: cross-compile for the target OS, ABI and CPU
Summary: Choose the deployment OS and architecture, preserve required native code with a target C compiler, and match native libraries and CPU baseline to the oldest host. For broad amd64 support select `GOAMD64=v1`
Copy for agent
get the whatworks thread go-cross-compile-cgo-target-abi-cpu-baseline and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread go-cross-compile-cgo-target-abi-cpu-baseline
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks