NationalSecurityAgency/ghidra · error
%s: option `-W %s' is ambiguous\n
Error message
%s: option `-W %s' is ambiguous\n
What it means
GNU getopt_long `-W` ambiguity diagnostic. The POSIX `-W foo` shorthand for `--foo` matched more than one long option (a prefix match) with no exact match, so getopt cannot decide which one. It consumes the rest of the token, advances optind, and returns '?'.
Source
Thrown at GPL/DemanglerGnu/src/demangler_gnu_v2_41/c/getopt.c:873
pfound = p;
indfound = option_index;
exact = 1;
break;
}
else if (pfound == NULL)
{
/* First nonexact match found. */
pfound = p;
indfound = option_index;
}
else
/* Second or later nonexact match found. */
ambig = 1;
}
if (ambig && !exact)
{
if (opterr)
fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"),
argv[0], argv[optind]);
nextchar += strlen (nextchar);
optind++;
return '?';
}
if (pfound != NULL)
{
option_index = indfound;
if (*nameend)
{
/* Don't test has_arg with >, because some C compilers don't
allow it to be used on enums. */
if (pfound->has_arg)
optarg = nameend + 1;
else
{
if (opterr)
fprintf (stderr, _("\View on GitHub (pinned to d5f144c24d)
Solutions
- Type the full long-option name after `-W` instead of an ambiguous abbreviation.
- Invoke via the `--name` form directly to avoid the `-W` shorthand.
- Rename long options so prefixes are unambiguous, or add an exact-match-only option.
- Disable `-W` processing by removing `W;` from optstring if the shorthand is not needed.
Example fix
// before: long options {"verbose"},{"version"}; invocation prog -W ver
// -> option `-W ver' is ambiguous
// after: use the full name or the -- form
// prog -W verbose
// prog --verbose Defensive patterns
Strategy: validation
Validate before calling
// reject ambiguous -W prefixes before getopt, or require full long names
if (strncmp(arg, "-W", 2) == 0 && isAmbiguousPrefix(arg+2, long_opts)) {
fprintf(stderr, "use the full --name\n");
} Prevention
- Discourage -W abbreviation; prefer --longname.
- Design long-option names with distinct first letters.
- Remove W; from optstring if -W shorthand is unneeded.
When it happens
Trigger: getopt_long supports `-W` via an optstring containing `W;`. The user passes `-W <prefix>` where <prefix> is a non-unique prefix of two or more long options (e.g. long opts `--verbose` and `--version` invoked as `-W ver`).
Common situations: Long-option names share a common prefix; abbreviation is relied upon and later becomes ambiguous after a new option is added.
Related errors
- %s: option `-W %s' doesn't allow an argument\n
- %s: unrecognized option `%c%s'\n
- %s: illegal option -- %c\n
- %s: invalid option -- %c\n
- %s: option requires an argument -- %c\n
AI-assisted analysis of NationalSecurityAgency/ghidra@d5f144c24d (2026-08-14).
Data as JSON: /api/errors/732171fc4d042dfa.
Report an issue: GitHub.