NationalSecurityAgency/ghidra · error
%s: unrecognized option `%c%s'
Error message
%s: unrecognized option `%c%s'
What it means
Counterpart to error 20 for the single-dash form. In getopt_long_only, when a token like `-foo` matches no long option AND its first character isn't a valid short option, getopt reports it as unrecognized. The `%c%s` format prints the leading character (usually `-` or `+`) followed by the option text.
Source
Thrown at GPL/DemanglerGnu/src/demangler_gnu_v2_24/c/getopt.c:768
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);
/* Increment `optind' when we start to process its last character. */
if (*nextchar == '\0')
++optind;View on GitHub (pinned to d5f144c24d)
Solutions
- Check `--help` for valid option names
- Use the correct dash convention (-- for long options, - for short)
- Fix the typo
Example fix
// before (getopt_long_only tool) ./c++filt -nstrip input // after ./c++filt -n input # or --strip-underscore
Defensive patterns
Strategy: validation
Validate before calling
// For getopt_long_only, check that single-dash tokens are valid long or short options
static int is_valid_opt_long_only(const char *token, const char *optstring, const struct option *longopts) {
if (!token || token[0] != '-' || token[1] == '\0') return 1; // not an option
const char *name = token + 1;
for (const struct option *o = longopts; o->name; o++) {
if (strcmp(o->name, name) == 0) return 1;
}
if (strchr(optstring, name[0]) != NULL) return 1;
return 0;
} Type guard
static int is_known_token(const char *tok, const char *optstring, const struct option *longopts) {
if (!tok || tok[0] != '-') return 0;
const char *name = tok + 1;
for (const struct option *o = longopts; o->name; o++)
if (strcmp(o->name, name) == 0) return 1;
return strchr(optstring, name[0]) != NULL;
} Try / catch
int c;
while ((c = getopt_long_only(argc, argv, optstring, longopts, NULL)) != -1) {
if (c == '?') { exit(EXIT_FAILURE); }
} Prevention
- Prefer --double-dash syntax for long options to avoid ambiguity
- Document which options are valid in --help
- Test CLI invocations with an argument validator in CI
When it happens
Trigger: getopt_long_only is in use; user passes `-unknown` or `+unknown`; my_index(optstring, *nextchar) returns NULL (first char not a valid short option). opterr must be non-zero.
Common situations: Passing a single-dash long-style option that doesn't exist; using getopt_long_only (common in tools like c++filt) and mistyping an option; confusing the option syntax of getopt_long vs getopt_long_only.
Related errors
- %s: unrecognized option `--%s'
- %s: illegal option -- %c
- %s: invalid option -- %c
- %s: option requires an argument -- %c
- %s: option `-W %s' is ambiguous
AI-assisted analysis of NationalSecurityAgency/ghidra@d5f144c24d (2026-08-14).
Data as JSON: /api/errors/78fee5f816ad6fe4.
Report an issue: GitHub.