{"record":{"id":"ffe404e649bd38ba","repo":"golang/go","slug":"s-c-source-files-not-supported-without-cgo","errorCode":null,"errorMessage":"%s: C source files not supported without cgo","messagePattern":"(.+?): C source files not supported without cgo","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/work/gc.go","lineNumber":728,"sourceCode":"\n\t// On OS X when using external linking to build a shared library,\n\t// the argument passed here to -o ends up recorded in the final\n\t// shared library in the LC_ID_DYLIB load command.\n\t// To avoid putting the temporary output directory name there\n\t// (and making the resulting shared library useless),\n\t// run the link in the output directory so that -o can name\n\t// just the final path element.\n\t// On Windows, DLL file name is recorded in PE file\n\t// export section, so do like on OS X.\n\t// On Linux, for a shared object, at least with the Gold linker,\n\t// the output file path is recorded in the .gnu.version_d section.\n\tdir, targetPath := filepath.Split(targetPath)\n\n\treturn b.Shell(root).run(dir, targetPath, cfgChangedEnv, cfg.BuildToolexec, base.Tool(\"link\"), \"-o\", targetPath, \"-importcfg\", importcfg, ldflags)\n}\n\nfunc (gcToolchain) cc(b *Builder, a *Action, ofile, cfile string) error {\n\treturn fmt.Errorf(\"%s: C source files not supported without cgo\", mkAbs(a.Package.Dir, cfile))\n}\n","sourceCodeStart":710,"sourceCodeEnd":730,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/work/gc.go#L710-L730","documentation":"The gcToolchain.cc method - the default gc compiler's C-compilation stub - unconditionally returns this error. It means a package contains .c (or other C source) files but CGO_ENABLED=0, so the gc toolchain has no way to compile them. The path is made absolute via mkAbs(a.Package.Dir, cfile) for clarity in the message.","triggerScenarios":"Fires in gcToolchain.cc when the build attempts to compile a C source file in a package while cgo is disabled (CGO_ENABLED=0 or CGO_ENABLED unset with no C compiler).","commonSituations":"Cross-compiling with CGO_ENABLED=0 while depending on a package with C sources, or building in a minimal container (scratch/alpine) without a C compiler.","solutions":["Enable cgo: `CGO_ENABLED=1 go build` (requires a working C compiler)","Remove the C source files or the dependency that brings them in","Add build tags to exclude C files for non-cgo builds"],"exampleFix":"// before\nCGO_ENABLED=0 go build ./...\n// after\nCGO_ENABLED=1 go build ./...","handlingStrategy":"validation","validationCode":"// Before a CGO_ENABLED=0 build, check for C source files\nif os.Getenv(\"CGO_ENABLED\") == \"0\" {\n    if matches, _ := filepath.Glob(\"*.c\"); len(matches) > 0 {\n        return fmt.Errorf(\"C files present but cgo disabled: %v\", matches)\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set CGO_ENABLED=1 (and install a C compiler) when a dependency has C sources","Guard C files with build tags so they are excluded from pure-Go builds","In minimal containers, install gcc/musl-gcc or drop the cgo dependency"],"tags":["go-toolchain","cgo","c-source","cross-compilation"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:31:55.035Z"}