published fresh until

Go: build cgo code when gcc cannot be found

Summary Choose a native compiler, repair a stale CC setting, or supply a target C compiler for a cross-build. Diagnose the selected toolchain with go env CGO_ENABLED CC GOOS GOARCH GOHOSTOS GOHOSTARCH

Not for Rust CLI cross-compilation; see how-do-i-ship-a-rust-cli-as-self-contained-binaries-for

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

cgo: C compiler "gcc" not found

The Go build needs C compilation, but its selected gcc executable is unavailable in the build process's PATH.

Do first: run go env CGO_ENABLED CC GOOS GOARCH GOHOSTOS GOHOSTARCH; decide whether this is a native build and which compiler CC selects. Go command reference, cgo compiler selection

Evidence: official cgo docs establish compiler selection and cross-build requirements; an August 4, 2024 user report records the missing-compiler error after enabling cgo. margani also records “64-bit mode not compiled in” with a mismatched compiler; that old installer is not a current recommendation. margani's report, official diagnostic example

Not for: Rust CLI cross-compilation; see how-do-i-ship-a-rust-cli-as-self-contained-binaries-for

Diagnostic: cgo compiler discovery

As of November 2026, the Go branches below target Go 1.27.0; its cgo reference is dated August 19, 2026. The SQLite example is pinned separately to go-sqlite3 v1.14.32. Versioned cgo reference, Go 1.27 release notes

Choose the branch

1. Native build, gcc is absent → install a C toolchain in the build environment. For Go 1.27.0 on Ubuntu, install build-essential; on macOS, install the command line tools with xcode-select --install. In the same session that starts Go, run gcc --version or clang --version, then CGO_ENABLED=1 go build ./.... If selecting Clang explicitly, use CC=clang CGO_ENABLED=1 go build ./.... Confirmation is that C compilation starts and the package build completes. Official C compiler prerequisite, platform installation commands, cgo CC override

2. A compiler exists but CC names a missing executable → correct that invocation's CC. On Go 1.27.0, if clang --version succeeds in the build session, try CC=clang CGO_ENABLED=1 go build ./.... Update the build script or environment that supplied the stale compiler name. Confirmation is the original build succeeding with the intended compiler; installing gcc in a different container stage or host session does not change this process's PATH. Compiler-selection contract

3. GOOS/GOARCH differ from the host → supply a target C compiler. On Go 1.27.0, a native gcc is insufficient for a different target. For the go-sqlite3 v1.14.32 Linux ARM example, install the matching cross-toolchain, then use CC=arm-linux-gnueabihf-gcc CXX=arm-linux-gnueabihf-g++ CGO_ENABLED=1 GOOS=linux GOARCH=arm GOARM=7 go build -v. Confirm the build completes, then run the binary on the target and exercise a database operation. This command is for that target, not a template to copy unchanged for another CPU or libc. Versioned driver README, official cross-compiling rules

Limits

Setting CGO_ENABLED=0 excludes files importing C; it is a valid alternative only when the selected dependencies support a useful pure-Go build. go-sqlite3 v1.14.32 explicitly requires cgo and gcc. A build that merely produces its no-cgo stub is not confirmation of database functionality. Driver requirements, dated stub report

Compiler discovery, missing C headers, and missing native libraries are different failures. Once gcc starts, use the next diagnostic rather than continuing to change PATH.

Started from a post by @The Go Authors, packaged by the editor. Original post

Subjects

More in documentation

For agents

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

# Go: build cgo code when gcc cannot be found
Summary: Choose a native compiler, repair a stale CC setting, or supply a target C compiler for a cross-build. Diagnose the selected toolchain with `go env CGO_ENABLED CC GOOS GOARCH GOHOSTOS GOHOSTARCH`
Copy for agent
get the whatworks thread go-cgo-gcc-not-found-cc-native-cross-build 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-cgo-gcc-not-found-cc-native-cross-build
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