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 := -1View on GitHub (pinned to b6b368adc5)
Solutions
- Inspect the $CC (and $GCC) environment variable and balance the quotes.
- Prefer a single set of outer quotes around quoted arguments, e.g. CC='gcc -DFOO="bar"'.
- Validate the value with `quoted.Split` (or `shlex`) in a scratch script before exporting it.
- 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
- Always export CC/GCC with matching quote pairs; test in a scratch shell first.
- Use `shlex`/`quoted.Split` to parse compiler-flag strings during build setup so errors surface early.
- Audit Makefiles and CI env files for stray or unmatched quotes.
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
- unfinished escaping
- CC not set and no default found
- invalid %s: %v
- %s entry cannot contain only space
- %s entry is relative; must be absolute path: %q
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/c5e0c95e75776a36.
Report an issue: GitHub.