golang/go · error

unclosed quote

Error message

unclosed quote

What it means

Thrown by splitQuoted (src/cmd/cgo/gcc.go) when, after consuming the entire input string, an opening quote character (single or double) was never closed. The function remembers the quote type in `quote`; if it is non-zero at end-of-string, the parse is incomplete.

Source

Thrown at src/cmd/cgo/gcc.go:180

			quoted = true
			quote = r
			continue
		case unicode.IsSpace(r):
			if quoted || i > 0 {
				quoted = false
				args = append(args, string(arg[:i]))
				i = 0
			}
			continue
		}
		arg[i] = r
		i++
	}
	if quoted || i > 0 {
		args = append(args, string(arg[:i]))
	}
	if quote != 0 {
		err = errors.New("unclosed quote")
	} else if escaped {
		err = errors.New("unfinished escaping")
	}
	return args, err
}

// loadDebug runs gcc to load debug information for the File. The debug
// information will be saved to the debugs field of the file, and be
// processed when Translate is called on the file later.
// loadDebug is called concurrently with different files.
func (f *File) loadDebug(p *Package) {
	for _, cref := range f.Ref {
		// Convert C.ulong to C.unsigned long, etc.
		cref.Name.C = cname(cref.Name.Go)
	}

	ft := fileTypedefs{typedefs: make(map[string]bool)}
	numTypedefs := -1

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Inspect the $CC (and $GCC) environment variable and balance the quotes.
  2. Prefer a single set of outer quotes around quoted arguments, e.g. CC='gcc -DFOO="bar"'.
  3. Validate the value with `quoted.Split` (or `shlex`) in a scratch script before exporting it.
  4. Unset CC/GCC temporarily to fall back to the default compiler and confirm the error source.

Example fix

// before
export CC='gcc -DFOO="bar'
// after
export CC='gcc -DFOO="bar"'
Defensive patterns

Strategy: validation

Validate before calling

// Pre-validate a CC/GCC value for balanced quotes before exporting it.
func quotesBalanced(s string) bool {
    var quote rune
    escaped := false
    for _, r := range s {
        if escaped { escaped = false; continue }
        if r == '\\' { escaped = true; continue }
        if quote != 0 { if r == quote { quote = 0 }; continue }
        if r == '"' || r == '\'' { quote = r }
    }
    return quote == 0
}

Prevention

When it happens

Trigger: splitQuoted receives a value with an unmatched quote. In cgo this value is typically the $CC / $GCC environment variable or a flag string split via quoted.Split. Example: CC='gcc -DFOO="bar' has an opening double quote with no closing quote.

Common situations: Mis-quoting CC/GCC environment variables in a Makefile, shell profile, or CI config; a stray trailing quote; copy-pasting a compiler invocation that lost its closing quote through shell expansion; CFLAGS with embedded spaces quoted incorrectly.

Related errors


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