{"record":{"id":"4f1e1afea4b99c75","repo":"golang/go","slug":"c-compiler-q-not-found-v","errorCode":null,"errorMessage":"C compiler %q not found: %v","messagePattern":"C compiler %q not found: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/cgo/gcc.go","lineNumber":1752,"sourceCode":"func checkGCCBaseCmd() ([]string, error) {\n\t// Use $CC if set, since that's what the build uses.\n\tvalue := os.Getenv(\"CC\")\n\tif value == \"\" {\n\t\t// Try $GCC if set, since that's what we used to use.\n\t\tvalue = os.Getenv(\"GCC\")\n\t}\n\tif value == \"\" {\n\t\tvalue = defaultCC(goos, goarch)\n\t}\n\targs, err := quoted.Split(value)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif len(args) == 0 {\n\t\treturn nil, errors.New(\"CC not set and no default found\")\n\t}\n\tif _, err := exec.LookPath(args[0]); err != nil {\n\t\treturn nil, fmt.Errorf(\"C compiler %q not found: %v\", args[0], err)\n\t}\n\treturn args[:len(args):len(args)], nil\n}\n\n// gccMachine returns the gcc -m flag to use, either \"-m32\", \"-m64\" or \"-marm\".\nfunc gccMachine() []string {\n\tswitch goarch {\n\tcase \"amd64\":\n\t\tif goos == \"darwin\" {\n\t\t\treturn []string{\"-arch\", \"x86_64\", \"-m64\"}\n\t\t}\n\t\treturn []string{\"-m64\"}\n\tcase \"arm64\":\n\t\tif goos == \"darwin\" {\n\t\t\treturn []string{\"-arch\", \"arm64\"}\n\t\t}\n\tcase \"386\":\n\t\treturn []string{\"-m32\"}","sourceCodeStart":1734,"sourceCodeEnd":1770,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/cgo/gcc.go#L1734-L1770","documentation":"Returned by the cgo CC resolver (gcc.go:1752) when exec.LookPath fails for the resolved C compiler name. The compiler name comes from the CC env var or defaultCC(goos, goarch); LookPath searches PATH and errors if no executable matches. This blocks cgo from compiling C/C++ sources.","triggerScenarios":"Building a package that uses cgo (imports \"C\") with CGO_ENABLED=1, where CC is unset and the default compiler (gcc/clang) is not on PATH, or where CC names a binary that does not exist. LookPath returns an error which is wrapped here.","commonSituations":"Fresh container/CI image without gcc/clang installed; CC set to a cross-compiler that is not installed; PATH missing /usr/bin or Homebrew's bin; building on a minimal alpine image without build-base; CC points to a typo'd path.","solutions":["Install a C compiler: apt-get install gcc / brew install gcc / dnf install gcc.","Set CC explicitly to a known-good compiler: `CC=gcc go build` or `CC=/usr/local/bin/gcc-13 go build`.","If you do not need cgo, set CGO_ENABLED=0 to skip C compilation entirely.","Verify with `which gcc` / `which clang` and that the CC env var (if set) points to an existing executable."],"exampleFix":"// before\n$ go build ./mypkg  // uses cgo, CC unset, no gcc on PATH -> error\n\n// after (option A: install compiler)\n$ sudo apt-get install -y gcc && go build ./mypkg\n\n// after (option B: disable cgo)\n$ CGO_ENABLED=0 go build ./mypkg\n\n// after (option C: point CC)\n$ CC=/opt/homebrew/bin/gcc-13 go build ./mypkg","handlingStrategy":"validation","validationCode":"func cgoCompilerAvailable() error {\n    cc := os.Getenv(\"CC\")\n    if cc == \"\" {\n        cc = \"gcc\" // defaultCC fallback\n    }\n    if _, err := exec.LookPath(cc); err != nil {\n        return fmt.Errorf(\"C compiler %q not on PATH: %w\", cc, err)\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Install gcc/clang in CI and dev images that build cgo packages.","Set CC explicitly to a known compiler when the default is missing.","Set CGO_ENABLED=0 for pure-Go builds to avoid needing a C compiler.","Verify with `which gcc` / `which clang` before building."],"tags":["cgo","build","c-compiler","path","toolchain"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:31:55.035Z"}