{"record":{"id":"2abfb9b86424dd38","repo":"golang/go","slug":"unknown-compiler-q","errorCode":null,"errorMessage":"unknown compiler %q","messagePattern":"unknown compiler %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/work/build.go","lineNumber":283,"sourceCode":"\nvar (\n\tBuildToolchain toolchain = noToolchain{}\n\tldBuildmode    string\n)\n\n// buildCompiler implements flag.Var.\n// It implements Set by updating both\n// BuildToolchain and buildContext.Compiler.\ntype buildCompiler struct{}\n\nfunc (c buildCompiler) Set(value string) error {\n\tswitch value {\n\tcase \"gc\":\n\t\tBuildToolchain = gcToolchain{}\n\tcase \"gccgo\":\n\t\tBuildToolchain = gccgoToolchain{}\n\tdefault:\n\t\treturn fmt.Errorf(\"unknown compiler %q\", value)\n\t}\n\tcfg.BuildToolchainName = value\n\tcfg.BuildContext.Compiler = value\n\treturn nil\n}\n\nfunc (c buildCompiler) String() string {\n\treturn cfg.BuildContext.Compiler\n}\n\nfunc init() {\n\tswitch build.Default.Compiler {\n\tcase \"gc\", \"gccgo\":\n\t\tbuildCompiler{}.Set(build.Default.Compiler)\n\t}\n}\n\ntype BuildFlagMask int","sourceCodeStart":265,"sourceCodeEnd":301,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/work/build.go#L265-L301","documentation":"buildCompiler.Set is the flag.Value for -compiler. It accepts only 'gc' (the standard Go compiler) and 'gccgo' (the GCC-based Go frontend). Any other value returns this error, and flag parsing aborts before any build work begins.","triggerScenarios":"Invoking 'go build -compiler=<x>' (or GOFLAGS=-compiler=<x>, or setting the compiler via -gcflags with a bad toolchain name) where <x> is not 'gc' or 'gccgo'. Commonly a typo like 'gcc' or 'llvm' or 'go'.","commonSituations":"Users coming from C ecosystems who try '-compiler=gcc'; tooling scripts that interpolate an unknown compiler name; copied GOFLAGS from another project.","solutions":["Use '-compiler=gccgo' for the GCC-based Go frontend (install gccgo first).","Omit -compiler entirely to use the default 'gc'.","Check GOFLAGS in the environment: 'go env GOFLAGS' and unset the bad value.","For C compiler selection in cgo, use CC= not -compiler."],"exampleFix":"// before\n$ go build -compiler=gcc ./...\n// error: unknown compiler \"gcc\"\n\n// after\n$ go build -compiler=gccgo ./...   # if you meant gccgo\n# or\n$ go build ./...                   # default gc compiler\n# for cgo C-compiler selection:\n$ CC=gcc go build ./...","handlingStrategy":"validation","validationCode":"var validCompilers = map[string]bool{\"gc\": true, \"gccgo\": true}\n\nfunc validateCompilerFlag(v string) error {\n    if !validCompilers[v] {\n        return fmt.Errorf(\"-compiler must be 'gc' or 'gccgo', got %q\", v)\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always cross-check -compiler values against the allowed set before invoking go.","Audit GOFLAGS in CI for unknown compiler names.","Use CC= for selecting the C compiler in cgo, not -compiler."],"tags":["build","compiler","flag-validation","gccgo"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}