go build_error ai_generated true

# runtime/cgo cgo: C compiler "gcc" not found: exec: "gcc": executable file not found in $PATH

ID: go/cgo-linker-error

Also available as: JSON · Markdown
88%Fix Rate
90%Confidence
50Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1 active

Root Cause

CGo requires a C compiler and linker. The build fails because gcc/clang is not installed, or C libraries referenced by #cgo directives are missing.

generic

Workarounds

  1. 92% success Install C build tools: apt-get install gcc libc6-dev
    sudo apt-get update && sudo apt-get install -y build-essential

    Sources: https://go.dev/doc/install/source

  2. 88% success Install the specific C library headers referenced by the Go package
    Read the cgo LDFLAGS/CFLAGS in the Go source, then install the corresponding -dev package (e.g., libsqlite3-dev)

    Sources: https://pkg.go.dev/cmd/cgo

Dead Ends

Common approaches that don't work:

  1. Set CGO_ENABLED=0 when the package genuinely requires CGo 80% fail

    Packages like go-sqlite3, libpcap bindings, and system crypto require CGo — disabling it causes missing symbol errors at link time or runtime

  2. Copy pre-compiled .so/.a files from another machine 70% fail

    Shared libraries are ABI-sensitive — compiled on a different glibc or architecture will produce cryptic linker errors

Error Chain

Leads to:
Preceded by:
Frequently confused with: