golang/go · error
missing =<value> in <pattern>=<value>
Error message
missing =<value> in <pattern>=<value>
What it means
Per-package flags (-gcflags, -ldflags, -asmflags, -gccgoflags) use a <pattern>=<flags> syntax when the value does not start with a dash. This error fires when the value contains no '=' character at all, making it impossible to separate the package pattern from the flags. The PerPackageFlag.set method checks for '=' via strings.Index and finds none.
Source
Thrown at src/cmd/go/internal/load/flag.go:58
}
// set is the implementation of Set, taking a cwd (current working directory) for easier testing.
func (f *PerPackageFlag) set(v, cwd string) error {
f.raw = v
f.present = true
match := func(_ *modload.Loader, p *Package) bool { return p.Internal.CmdlinePkg || p.Internal.CmdlineFiles } // default predicate with no pattern
// For backwards compatibility with earlier flag splitting, ignore spaces around flags.
v = strings.TrimSpace(v)
if v == "" {
// Special case: -gcflags="" means no flags for command-line arguments
// (overrides previous -gcflags="-whatever").
f.values = append(f.values, ppfValue{match, []string{}})
return nil
}
if !strings.HasPrefix(v, "-") {
i := strings.Index(v, "=")
if i < 0 {
return fmt.Errorf("missing =<value> in <pattern>=<value>")
}
if i == 0 {
return fmt.Errorf("missing <pattern> in <pattern>=<value>")
}
if v[0] == '\'' || v[0] == '"' {
return fmt.Errorf("parameter may not start with quote character %c", v[0])
}
pattern := strings.TrimSpace(v[:i])
match = MatchPackage(pattern, cwd)
v = v[i+1:]
}
flags, err := quoted.Split(v)
if err != nil {
return err
}
if flags == nil {
flags = []string{}
}View on GitHub (pinned to b6b368adc5)
Solutions
- If you want flags applied to the packages on the command line, prefix the value with '-': go build -gcflags="-N -l".
- If you want flags for a specific package pattern, use <pattern>=<flags>: go build -gcflags="runtime=-N -l".
- For all packages in your module: go build -gcflags="./...=-N -l".
Example fix
// before — no = sign, no leading - go build -gcflags=. // after — flags with leading - apply to command-line packages go build -gcflags="-N -l" // or — pattern=value syntax go build -gcflags="./...=-N -l"
Defensive patterns
Strategy: validation
Validate before calling
// Validate per-package flag syntax before passing to go build.
func validatePerPackageFlag(v string) error {
v = strings.TrimSpace(v)
if v == "" || strings.HasPrefix(v, "-") {
return nil // valid: empty or flags-only form
}
if !strings.Contains(v, "=") {
return fmt.Errorf("missing =<value> in <pattern>=<value>: %q", v)
}
return nil
} Prevention
- Use leading '-' for flags meant for command-line packages: -gcflags="-N -l".
- Use pattern=value for package-specific flags: -gcflags="runtime=-N -l".
- Test flag syntax in a dry run before CI.
When it happens
Trigger: Passing -gcflags=. or -ldflags=myproject — a value that doesn't start with '-' and has no '='. The parser expects either -gcflags="-N -l" (flags apply to command-line packages) or -gcflags="./...=-N -l" (pattern=value syntax).
Common situations: Confusing the flag syntax — forgetting the '=' between pattern and flags. Migrating from older Go versions with different flag handling conventions. Shell quoting issues that strip the '='. Typing a bare pattern or package name without flags.
Related errors
- missing <pattern> in <pattern>=<value>
- parameter may not start with quote character %c
- missing key=value
- total length of command line and environment variables excee
- parse error
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/d9e285a69efdefe0.
Report an issue: GitHub.