golang/go · error

must have SWIG version >= 3.0.6

Error message

must have SWIG version >= 3.0.6

What it means

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.

Source

Thrown at src/cmd/go/internal/work/exec.go:3678

	out, err := sh.runOut(".", nil, "swig", "-version")
	if err != nil {
		return err
	}
	re := regexp.MustCompile(`[vV]ersion +(\d+)([.]\d+)?([.]\d+)?`)
	matches := re.FindSubmatch(out)
	if matches == nil {
		// Can't find version number; hope for the best.
		return nil
	}

	major, err := strconv.Atoi(string(matches[1]))
	if err != nil {
		// Can't find version number; hope for the best.
		return nil
	}
	const errmsg = "must have SWIG version >= 3.0.6"
	if major < 3 {
		return errors.New(errmsg)
	}
	if major > 3 {
		// 4.0 or later
		return nil
	}

	// We have SWIG version 3.x.
	if len(matches[2]) > 0 {
		minor, err := strconv.Atoi(string(matches[2][1:]))
		if err != nil {
			return nil
		}
		if minor > 0 {
			// 3.1 or later
			return nil
		}
	}

View on GitHub (pinned to b6b368adc5)

Solutions

  1. 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.
  2. Verify the resolved binary: `which swig && swig -version`. Fix PATH ordering if multiple swig binaries exist.
  3. Pin a known-good SWIG in your Dockerfile/CI image and rebuild.
  4. If you cannot upgrade SWIG, remove the .swig/.swigcxx files and use plain cgo instead.

Example fix

# before
$ swig -version | head -1
SWIG Version 2.0.12
$ go install ./...
# -> must have SWIG version >= 3.0.6

# after
$ brew upgrade swig
$ swig -version | head -1
SWIG Version 4.2.1
$ go install ./...
Defensive patterns

Strategy: validation

Validate before calling

func requiredSwigOK() error {
    out, err := exec.Command("swig", "-version").CombinedOutput()
    if err != nil { return fmt.Errorf("swig not installed: %w", err) }
    m := regexp.MustCompile(`[vV]ersion +(\d+)`).FindSubmatch(out)
    if m == nil { return errors.New("cannot determine swig version") }
    major, _ := strconv.Atoi(string(m[1]))
    if major < 3 { return errors.New("need SWIG >= 3.0.6 (got major " + string(m[1]) + ")") }
    return nil
}

Type guard

func swigMajorAtLeast(min int) bool {
    out, _ := exec.Command("swig", "-version").Output()
    m := regexp.MustCompile(`[vV]ersion +(\d+)`).FindSubmatch(out)
    if m == nil { return false }
    v, _ := strconv.Atoi(string(m[1]))
    return v >= min
}

Prevention

When it happens

Trigger: 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.

Common situations: 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).

Related errors


AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12). Data as JSON: /api/errors/1c18e962e7094276. Report an issue: GitHub.