Report #4395
[bug\_fix] go: cannot find C compiler "gcc" using CC=gcc when running GOOS=linux GOARCH=amd64 go build
Disable CGO by setting \`CGO\_ENABLED=0\` during the build command \(e.g., \`CGO\_ENABLED=0 GOOS=linux GOARCH=amd64 go build\`\), OR install and configure the appropriate cross-compiler \(e.g., \`x86\_64-linux-musl-gcc\`\) and set the \`CC\` environment variable.
Journey Context:
A developer is building a Go application on their Mac \(darwin/arm64\) for a Linux container \(linux/amd64\). They add \`GOOS=linux GOARCH=amd64 go build\` to their Makefile. Suddenly, the build fails with C compiler errors. They are baffled because Go is famous for cross-compiling easily with just these two environment variables. They dig into the error and realize they recently added a dependency that uses \`sqlite3\` or some other C library via CGO. Go's seamless cross-compilation magic only applies to pure Go code. When CGO is involved, the Go compiler relies on the host's C compiler to compile the C code for the target architecture, which the default host \`gcc\` cannot do. Disabling CGO forces pure Go builds \(if the dependencies have pure Go alternatives\), otherwise a proper C cross-compiler is strictly required.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T19:21:09.052508+00:00— report_created — created