golang/go · error
-asan: C compiler is not gcc or clang
Error message
-asan: C compiler is not gcc or clang
What it means
Thrown by compilerRequiredAsanVersion when -asan is requested but the detected C compiler is neither gcc nor clang (compiler.name falls through to the default case). The Go -asan integration only supports libasan from gcc or clang; other compilers are rejected outright.
Source
Thrown at src/cmd/go/internal/work/init.go:455
compiler, err := compilerVersion()
if err != nil {
return fmt.Errorf("-asan: the version of $(go env CC) could not be parsed")
}
switch compiler.name {
case "gcc":
if runtime.GOARCH == "ppc64le" && compiler.major < 9 {
return fmt.Errorf("-asan is not supported with %s compiler %d.%d\n", compiler.name, compiler.major, compiler.minor)
}
if compiler.major < 7 {
return fmt.Errorf("-asan is not supported with %s compiler %d.%d\n", compiler.name, compiler.major, compiler.minor)
}
case "clang":
if compiler.major < 9 {
return fmt.Errorf("-asan is not supported with %s compiler %d.%d\n", compiler.name, compiler.major, compiler.minor)
}
default:
return fmt.Errorf("-asan: C compiler is not gcc or clang")
}
return nil
}
View on GitHub (pinned to b6b368adc5)
Solutions
- Set CC to a supported compiler: `CC=gcc go build -asan` or `CC=clang go build -asan`.
- Drop -asan if Asan is not required for this target.
- If you wrote a CC wrapper, make `-dumpversion`/`--version` output a recognizable gcc or clang signature.
- Verify detection: `$(go env CC) -dumpversion`.
Example fix
// before // CC=tcc go build -asan (not gcc/clang) // after // CC=clang go build -asan
Defensive patterns
Strategy: validation
Validate before calling
// Confirm CC is gcc or clang before -asan
cc := strings.TrimSpace(string(execMust("go", "env", "CC")))
for _, args := range [][]string{{cc, "--version"}, {cc, "-v"}} {
out, _ := exec.Command(args[0], args[1:]...).CombinedOutput()
s := string(out)
if strings.Contains(s, "gcc") || strings.Contains(s, "clang") || strings.Contains(s, "LLVM") {
return // ok
}
}
log.Fatalf("-asan requires gcc or clang; %s is neither", cc) Prevention
- Do not point CC at tcc/msvc/icx-classified wrappers for -asan.
- Document supported compilers for Asan builds.
- Run the detection snippet in CI before -asan tests.
When it happens
Trigger: Run `go build -asan` with CGO_ENABLED=1 where `$(go env CC) -dumpversion` returns a vendor string compilerVersion() recognizes but does not classify as gcc/clang (e.g. MSVC via a wrapper, TinyCC (tcc), Intel icc/icx older classification, or a custom wrapper).
Common situations: CC overridden to a non-gcc/clang toolchain; Windows builds with a non-gcc/clang compiler; embedded vendor compilers; a CC wrapper script that does not echo a recognizable gcc/clang dumpversion.
Related errors
- -asan: the version of $(go env CC) could not be parsed
- -asan is not supported with %s compiler %d.%d\n
- unterminated quoted string in pkgconf output
- broken character escaping in pkgconf output
- must have SWIG version >= 3.0.6
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/51d591e089fd8ca2.
Report an issue: GitHub.