NationalSecurityAgency/ghidra · error
%s: unrecognized option `%c%s'\n
Error message
%s: unrecognized option `%c%s'\n
What it means
GNU getopt reports an unrecognized option. The `%c%s` form fires for a short-style token (`-x` or `+x`) whose first character is not present in the optstring passed to getopt/getopt_long. The message goes to stderr and getopt returns '?' to the caller; it does not abort. Suppressible by setting opterr = 0.
Source
Thrown at GPL/DemanglerGnu/src/demangler_gnu_v2_41/c/getopt.c:767
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
- Add the missing option character to the optstring (append ':' if it takes an argument).
- Check the offending letter via optopt and correct the typo in the invocation or the optstring.
- If the token is intentionally unsupported, set opterr = 0 and handle the returned '?' with a custom message.
- With getopt_long_only, rename single-character long options that collide with short-option letters.
Example fix
// before
while ((c = getopt_long(argc, argv, "ab:c", lo, &i)) != -1) { ... }
// invocation: prog -z -> unrecognized option `-z'
// after (add 'z', or suppress + handle)
while ((c = getopt_long(argc, argv, "ab:cz", lo, &i)) != -1) { ... } Defensive patterns
Strategy: validation
Validate before calling
// before getopt, confirm option letters you accept are all in optstring
const char *expected = "ab:cz";
if (strchr(expected, userChar) == NULL) { fprintf(stderr, "bad -%c\n", userChar); }
opterr = 0; // silence builtin; handle '?' yourself Prevention
- Generate usage text and optstring from one source to prevent drift.
- Always branch on getopt's '?' return and inspect optopt.
- Avoid single-char long-option names when using getopt_long_only.
When it happens
Trigger: getopt/getopt_long is invoked with an optstring that does not contain the option letter the user typed (e.g. prog run as `-z` while optstring is "ab:c"). Also reached under getopt_long_only when a single-dash token's leading char is neither in optstring nor a unique long-option prefix.
Common situations: A flag was added to the usage/help text but never added to the optstring; a typo in the option letter; getopt_long_only ambiguity between a short cluster and a long name.
Related errors
- %s: illegal option -- %c\n
- %s: invalid option -- %c\n
- %s: option requires an argument -- %c\n
- %s: option `-W %s' is ambiguous\n
- %s: option `-W %s' doesn't allow an argument\n
AI-assisted analysis of NationalSecurityAgency/ghidra@d5f144c24d (2026-08-14).
Data as JSON: /api/errors/a79d10eca61ac0e4.
Report an issue: GitHub.