{"record":{"id":"1b983928d4d9beb6","repo":"golang/go","slug":"s-invalid-cgo-verb-s","errorCode":null,"errorMessage":"%s: invalid #cgo verb: %s","messagePattern":"(.+?): invalid #cgo verb: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/modindex/build.go","lineNumber":498,"sourceCode":"\t\t\t// Change relative paths to absolute.\n\t\t\tctxt.makePathsAbsolute(args, di.Dir)\n\t\t}\n\n\t\tswitch verb {\n\t\tcase \"CFLAGS\":\n\t\t\tdi.CgoCFLAGS = append(di.CgoCFLAGS, args...)\n\t\tcase \"CPPFLAGS\":\n\t\t\tdi.CgoCPPFLAGS = append(di.CgoCPPFLAGS, args...)\n\t\tcase \"CXXFLAGS\":\n\t\t\tdi.CgoCXXFLAGS = append(di.CgoCXXFLAGS, args...)\n\t\tcase \"FFLAGS\":\n\t\t\tdi.CgoFFLAGS = append(di.CgoFFLAGS, args...)\n\t\tcase \"LDFLAGS\":\n\t\t\tdi.CgoLDFLAGS = append(di.CgoLDFLAGS, args...)\n\t\tcase \"pkg-config\":\n\t\t\tdi.CgoPkgConfig = append(di.CgoPkgConfig, args...)\n\t\tdefault:\n\t\t\treturn fmt.Errorf(\"%s: invalid #cgo verb: %s\", filename, orig)\n\t\t}\n\t}\n\treturn nil\n}\n\n// expandSrcDir expands any occurrence of ${SRCDIR}, making sure\n// the result is safe for the shell.\nfunc expandSrcDir(str string, srcdir string) (string, bool) {\n\t// \"\\\" delimited paths cause safeCgoName to fail\n\t// so convert native paths with a different delimiter\n\t// to \"/\" before starting (eg: on windows).\n\tsrcdir = filepath.ToSlash(srcdir)\n\n\tchunks := strings.Split(str, \"${SRCDIR}\")\n\tif len(chunks) < 2 {\n\t\treturn str, safeCgoName(str)\n\t}\n\tok := true","sourceCodeStart":480,"sourceCodeEnd":516,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/modindex/build.go#L480-L516","documentation":"Final saveCgo failure: the verb token extracted from a #cgo line is not one of the recognized verbs CFLAGS, CPPFLAGS, CXXFLAGS, FFLAGS, LDFLAGS, or pkg-config. Reached at the default branch of the switch on `verb`. The %s fields are filename and the original line so the user can see the unknown verb.","triggerScenarios":"Authoring a cgo directive with a typo'd or unsupported verb such as `#cgo LDLIBS: -lm`, `#cgo FLAGS: -O2`, or `#cgo GOTRACEBACK: 2`.","commonSituations":"Misspelling LDFLAGS as LDLIBS; assuming cgo supports arbitrary key/value pairs; using GCC-specific flags names that cgo does not recognize.","solutions":["Use one of the supported verbs: CFLAGS, CPPFLAGS, CXXFLAGS, FFLAGS, LDFLAGS, or pkg-config.","Move unrelated compiler flags into CGO_* environment variables or your build system instead of // #cgo lines.","For pkg-config dependencies use `#cgo pkg-config: foo bar`."],"exampleFix":"// before\n// #cgo LDLIBS: -lm\n// after\n// #cgo LDFLAGS: -lm","handlingStrategy":"validation","validationCode":"// Validate cgo verbs before build.\nvar validCgoVerbs = map[string]bool{\n    \"CFLAGS\": true, \"CPPFLAGS\": true, \"CXXFLAGS\": true,\n    \"FFLAGS\": true, \"LDFLAGS\": true, \"pkg-config\": true,\n}\n\nfunc lintCgoVerbValue(line string) error {\n    t := strings.TrimSpace(line)\n    if !strings.HasPrefix(t, \"#cgo\") {\n        return nil\n    }\n    head, _, _ := strings.Cut(strings.TrimPrefix(t, \"#cgo\"), \":\")\n    fields := strings.Fields(head)\n    if len(fields) == 0 {\n        return nil\n    }\n    if !validCgoVerbs[fields[len(fields)-1]] {\n        return fmt.Errorf(\"unknown cgo verb %q\", fields[len(fields)-1])\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep a whitelist of cgo verbs in repo docs.","Code-review cgo directive changes against that whitelist."],"tags":["cgo","build-directives","configuration"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}