Report #1211
[bug\_fix] cgo: C compiler "gcc" not found: exec: "gcc" executable file not found in %PATH% package example/cgosqlite: build constraints exclude all Go files in /go/pkg/mod/...
If the package requires cgo, install a C compiler \(e.g., \`apt-get install gcc\` on Debian, \`apk add build-base\` on Alpine, or \`xcode-select --install\` on macOS\) and ensure \`CGO\_ENABLED=1\`. If the package has a pure-Go fallback and you do not need cgo, explicitly set \`CGO\_ENABLED=0\` so the non-cgo implementation file is selected. For cross-compilation, you must also set \`CC\` to a matching cross-compiler.
Journey Context:
You build a Go service in a minimal Docker image based on \`golang:alpine\` and the build fails with \`cgo: C compiler "gcc" not found\` followed by \`build constraints exclude all Go files\`. You inspect the package and see it imports "C" to bind a SQLite library. Because the image has no gcc and Go cannot find a default C compiler, it implicitly sets \`CGO\_ENABLED=0\`. Files with \`import "C"\` carry an implicit \`//go:build cgo\` constraint, so they are excluded from the build. When every file in the package has that constraint, Go reports that no files are left. The fix is either adding \`build-base\` to the image so cgo can compile the bindings, or, if the package supports it, building with \`CGO\_ENABLED=0\` to select a pure-Go implementation.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-13T18:59:12.824697+00:00— report_created — created