{"record":{"id":"9e3bd8fce5cd88be","repo":"golang/go","slug":"cc-not-set-and-no-default-found","errorCode":null,"errorMessage":"CC not set and no default found","messagePattern":"CC not set and no default found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/cgo/gcc.go","lineNumber":1749,"sourceCode":"//\n// checkGCCBaseCmd confirms that the compiler exists in PATH, returning\n// an error if it does not.\nfunc 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\"}","sourceCodeStart":1731,"sourceCodeEnd":1767,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/cgo/gcc.go#L1731-L1767","documentation":"Thrown by checkGCCBaseCmd when no C compiler can be determined: $CC is empty, $GCC is empty, defaultCC(goos,goarch) returned an empty string, and splitting that empty value produced zero arguments. cgo requires a working C compiler to invoke gcc for parsing C debug info.","triggerScenarios":"Building a package that uses cgo (imports \"C\") on a system where no CC/GCC environment variable is set and the Go build has no compiled-in default compiler for the GOOS/GOARCH pair. Practically, this means the toolchain's defaultCC returned \"\" — e.g. an unusual target with no default.","commonSituations":"Cross-compiling to an exotic target without setting CC; a stripped/minimal toolchain build where defaultCC returns empty; CI image that removes gcc/clang and clears CC; building with CGO_ENABLED=1 but no compiler installed and no default defined.","solutions":["Set the CC environment variable to an absolute path of an installed C compiler, e.g. export CC=/usr/bin/gcc.","If you do not need cgo, build with CGO_ENABLED=0.","Install gcc or clang (e.g. apt-get install build-essential) and retry.","Verify the compiler is on PATH with `exec.LookPath` semantics (which checkGCCBaseCmd uses next)."],"exampleFix":"// before (no compiler, no default)\ngo build ./...\n// after\nexport CC=/usr/bin/gcc\ngo build ./...","handlingStrategy":"validation","validationCode":"// Ensure a C compiler is reachable before invoking cgo.\nimport \"os/exec\"\nfunc resolveCC() (string, error) {\n    for _, v := range []string{os.Getenv(\"CC\"), os.Getenv(\"GCC\"), \"gcc\", \"clang\", \"cc\"} {\n        if v == \"\" { continue }\n        if _, err := exec.LookPath(v); err == nil { return v, nil }\n    }\n    return \"\", errors.New(\"no C compiler found\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set CC to an absolute path in CI to make the compiler unambiguous.","Set CGO_ENABLED=0 for pure-Go builds to avoid needing a C compiler entirely.","Install build-essential (or platform equivalent) in build images."],"tags":["cgo","cc","compiler","environment","cross-compile"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}