NationalSecurityAgency/ghidra · warning

%s: option `%s' is ambiguous

Error message

%s: option `%s' is ambiguous

What it means

GNU getopt's long-option matcher: when an abbreviated long option (e.g. --ver for --verbose) matches more than one defined option and no exact match was found, it sets the ambiguous flag and, if opterr is set, prints this message and returns '?'. It is a usage error in the invoking program's command line, surfaced by getopt to stderr.

Source

Thrown at GPL/DemanglerGnu/src/demangler_gnu_v2_24/c/getopt.c:687

		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 `%s' is ambiguous\n"),
		     argv[0], argv[optind]);
	  nextchar += strlen (nextchar);
	  optind++;
	  optopt = 0;
	  return '?';
	}

      if (pfound != NULL)
	{
	  option_index = indfound;
	  optind++;
	  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

View on GitHub (pinned to d5f144c24d)

Solutions

  1. Spell the long option in full (use --version, not --ver) to avoid prefix ambiguity.
  2. Run the tool's --help to see exact option names and choose a longer unique prefix.
  3. Switch to the single-letter short form if one exists for that option.
  4. Update scripts after adding new options whose names create new prefix collisions.

Example fix

# before (program defines --version and --verbose)
$ tool --ver
... option `--ver' is ambiguous

# after - use the full name
$ tool --version
Defensive patterns

Strategy: validation

Validate before calling

// Validate the option prefix is unique against the program's known options before invoking
std::vector<std::string> matches = optionsStartingWith(prefix);
if (matches.size() != 1) {
    fprintf(stderr, "ambiguous or unknown option prefix: %s\n", prefix.c_str());
    exit(2);
}

Type guard

boolean isUniqueLongPrefix(String prefix, List<String> longOptions) {
    long matchCount = longOptions.stream().filter(o -> o.startsWith(prefix)).count();
    return matchCount == 1;
}

Try / catch

// getopt prints to stderr and returns '?'; the program usually exits non-zero.
int rc = run_child({"tool", "--" + prefix, ...});
if (rc != 0 && stderr_contains("is ambiguous")) {
    // re-run with the fully spelled-out option name
}

Prevention

When it happens

Trigger: Passing a long-option prefix that uniquely matches nothing because two or more options share that prefix, with no exact full name given. For example, if both --verbose and --version exist, '--ver' is ambiguous.

Common situations: Typing a short abbreviation of a long flag where the program defines multiple options with that prefix; new option added that shadows a previously-unique abbreviation in existing scripts; copy-paste of a flag from a different program version.

Related errors


AI-assisted analysis of NationalSecurityAgency/ghidra@d5f144c24d (2026-08-14). Data as JSON: /api/errors/c317529f570cb95d. Report an issue: GitHub.