{"record":{"id":"1c18e962e7094276","repo":"golang/go","slug":"must-have-swig-version-3-0-6","errorCode":null,"errorMessage":"must have SWIG version >= 3.0.6","messagePattern":"must have SWIG version >= 3\\.0\\.6","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/work/exec.go","lineNumber":3678,"sourceCode":"\tout, err := sh.runOut(\".\", nil, \"swig\", \"-version\")\n\tif err != nil {\n\t\treturn err\n\t}\n\tre := regexp.MustCompile(`[vV]ersion +(\\d+)([.]\\d+)?([.]\\d+)?`)\n\tmatches := re.FindSubmatch(out)\n\tif matches == nil {\n\t\t// Can't find version number; hope for the best.\n\t\treturn nil\n\t}\n\n\tmajor, err := strconv.Atoi(string(matches[1]))\n\tif err != nil {\n\t\t// Can't find version number; hope for the best.\n\t\treturn nil\n\t}\n\tconst errmsg = \"must have SWIG version >= 3.0.6\"\n\tif major < 3 {\n\t\treturn errors.New(errmsg)\n\t}\n\tif major > 3 {\n\t\t// 4.0 or later\n\t\treturn nil\n\t}\n\n\t// We have SWIG version 3.x.\n\tif len(matches[2]) > 0 {\n\t\tminor, err := strconv.Atoi(string(matches[2][1:]))\n\t\tif err != nil {\n\t\t\treturn nil\n\t\t}\n\t\tif minor > 0 {\n\t\t\t// 3.1 or later\n\t\t\treturn nil\n\t\t}\n\t}\n","sourceCodeStart":3660,"sourceCodeEnd":3696,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/work/exec.go#L3660-L3696","documentation":"Thrown by swigDoVersionCheck in cmd/go/internal/work when `swig -version` reports a major version below 3 (i.e. SWIG 1.x or 2.x). The go command requires SWIG >= 3.0.6 for cgo+SWIG interop; older versions lack the -intgosize option and have incompatible Go code generation. The check parses the version via regex and short-circuits any major < 3 immediately.","triggerScenarios":"Building a package containing .swig or .swigcxx files with SWIG 2.0.x installed (or any 1.x/2.x). A system that ships an ancient swig (some enterprise distros). PATH resolving to an old swig binary before a newer one.","commonSituations":"CI images that bundle an old swig. Local installations where `brew install swig` was never upgraded. Container base images pinned years ago. Misordered PATH pointing at /usr/bin/swig (old) instead of /usr/local/bin/swig (new).","solutions":["Install SWIG >= 3.0.6 — preferably the latest stable (4.x); on Debian/Ubuntu `apt install swig`, on macOS `brew install swig`, or build from source.","Verify the resolved binary: `which swig && swig -version`. Fix PATH ordering if multiple swig binaries exist.","Pin a known-good SWIG in your Dockerfile/CI image and rebuild.","If you cannot upgrade SWIG, remove the .swig/.swigcxx files and use plain cgo instead."],"exampleFix":"# before\n$ swig -version | head -1\nSWIG Version 2.0.12\n$ go install ./...\n# -> must have SWIG version >= 3.0.6\n\n# after\n$ brew upgrade swig\n$ swig -version | head -1\nSWIG Version 4.2.1\n$ go install ./...","handlingStrategy":"validation","validationCode":"func requiredSwigOK() error {\n    out, err := exec.Command(\"swig\", \"-version\").CombinedOutput()\n    if err != nil { return fmt.Errorf(\"swig not installed: %w\", err) }\n    m := regexp.MustCompile(`[vV]ersion +(\\d+)`).FindSubmatch(out)\n    if m == nil { return errors.New(\"cannot determine swig version\") }\n    major, _ := strconv.Atoi(string(m[1]))\n    if major < 3 { return errors.New(\"need SWIG >= 3.0.6 (got major \" + string(m[1]) + \")\") }\n    return nil\n}","typeGuard":"func swigMajorAtLeast(min int) bool {\n    out, _ := exec.Command(\"swig\", \"-version\").Output()\n    m := regexp.MustCompile(`[vV]ersion +(\\d+)`).FindSubmatch(out)\n    if m == nil { return false }\n    v, _ := strconv.Atoi(string(m[1]))\n    return v >= min\n}","tryCatchPattern":null,"preventionTips":["Pin SWIG >= 4.x in your Dockerfile/CI image.","Document the SWIG requirement for contributors building the cgo+SWIG packages.","Run `swig -version` in a setup step to fail fast with a clear message."],"tags":["go-toolchain","swig","cgo","version","dependency"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}