NationalSecurityAgency/ghidra · error

%s: unrecognized option `--%s'\n

Error message

%s: unrecognized option `--%s'\n

What it means

In getopt (v2_41), a `--long-option` token matches no entry in longopts and (in getopt_long_only) isn't a valid short option. Identical condition to error 20 but in the v2_41 codebase. opterr is non-zero and the program returns '?' for the token.

Source

Thrown at GPL/DemanglerGnu/src/demangler_gnu_v2_41/c/getopt.c:763

	    {
	      *(pfound->flag) = pfound->val;
	      return 0;
	    }
	  return pfound->val;
	}

      /* Can't find it as a long option.  If this is not getopt_long_only,
	 or the option starts with '--' or is not a valid short
	 option, then it's an error.
	 Otherwise interpret it as a short option.  */
      if (!long_only || argv[optind][1] == '-'
	  || my_index (optstring, *nextchar) == NULL)
	{
	  if (opterr)
	    {
	      if (argv[optind][1] == '-')
		/* --option */
		fprintf (stderr, _("%s: unrecognized option `--%s'\n"),
			 argv[0], nextchar);
	      else
		/* +option or -option */
		fprintf (stderr, _("%s: unrecognized option `%c%s'\n"),
			 argv[0], argv[optind][0], nextchar);
	    }
	  nextchar = (char *) "";
	  optind++;
	  optopt = 0;
	  return '?';
	}
    }

  /* Look at and handle the next short option-character.  */

  {
    char c = *nextchar++;
    char *temp = my_index (optstring, c);

View on GitHub (pinned to d5f144c24d)

Solutions

  1. Run `--help` to see valid options
  2. Fix the typo
  3. Verify the tool version supports this option

Example fix

// before
./c++filt --nouput input
// after
./c++filt --no-output input  # or remove the invalid option
Defensive patterns

Strategy: validation

Validate before calling

// Validate --long-options against the longopts table before calling getopt
static int validate_long_options(int argc, char *const argv[], const struct option *longopts) {
    for (int i = 1; i < argc; i++) {
        if (argv[i][0] != '-' || argv[i][1] != '-' || argv[i][2] == '\0') continue;
        const char *name = argv[i] + 2;
        const char *eq = strchr(name, '=');
        size_t len = eq ? (size_t)(eq - name) : strlen(name);
        int found = 0;
        for (const struct option *o = longopts; o->name; o++) {
            if (strncmp(o->name, name, len) == 0 && strlen(o->name) == len) { found = 1; break; }
        }
        if (!found) { fprintf(stderr, "Unknown option: --%.*s\n", (int)len, name); return 0; }
    }
    return 1;
}

Type guard

static int is_known_long_opt(const char *token, const struct option *longopts) {
    if (!token || token[0] != '-' || token[1] != '-') return 0;
    const char *name = token + 2;
    const char *eq = strchr(name, '=');
    size_t len = eq ? (size_t)(eq - name) : strlen(name);
    for (const struct option *o = longopts; o->name; o++)
        if (strlen(o->name) == len && strncmp(o->name, name, len) == 0) return 1;
    return 0;
}

Try / catch

int c;
while ((c = getopt_long(argc, argv, optstring, longopts, NULL)) != -1) {
    if (c == '?') {
        fprintf(stderr, "Usage: %s [options]\n", argv[0]);
        exit(EXIT_FAILURE);
    }
}

Prevention

When it happens

Trigger: User passes `--unknown` where no longopts entry matches; in getopt_long_only, my_index(optstring, *nextchar) is also NULL. opterr is non-zero.

Common situations: Typo in a long option name; option from a different version; copy-pasted command from incompatible documentation.

Related errors


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