NationalSecurityAgency/ghidra · error
%s: unrecognized option `--%s'
Error message
%s: unrecognized option `--%s'
What it means
GNU getopt emits this when a `--long-option` token matches no entry in the longopts table. The function walks all long options, finds no exact or prefix match, and (in getopt_long_only) confirms the first character isn't a valid short option. If opterr is non-zero (the default), it prints this diagnostic to stderr and returns '?' for the token.
Source
Thrown at GPL/DemanglerGnu/src/demangler_gnu_v2_24/c/getopt.c:764
{
*(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
- Run the tool with `--help` to list valid long options
- Correct the typo in the option name
- Confirm the tool version matches the documentation you followed
Example fix
// before ./c++filt --verbsoe input.txt // after ./c++filt --verbose input.txt
Defensive patterns
Strategy: validation
Validate before calling
// Validate that all long options in argv exist in the longopts table
#include <string.h>
static int is_known_long_opt(const char *token, const struct option *longopts) {
const char *name = token + 2; // skip "--"
const char *eq = strchr(name, '=');
size_t len = eq ? (size_t)(eq - name) : strlen(name);
for (const struct option *o = longopts; o->name != NULL; o++) {
if (strncmp(o->name, name, len) == 0 && strlen(o->name) == len)
return 1;
}
return 0;
}
// Before calling getopt_long, scan argv for unknown --options
for (int i = 1; i < argc; i++) {
if (argv[i][0] == '-' && argv[i][1] == '-' && argv[i][2] != '\0') {
if (!is_known_long_opt(argv[i], longopts))
fprintf(stderr, "Warning: unknown option %s\n", argv[i]);
}
} Type guard
static int is_valid_long_option(const char *opt, const struct option *longopts) {
if (!opt || opt[0] != '-' || opt[1] != '-') return 0;
const char *name = opt + 2;
for (const struct option *o = longopts; o->name; o++) {
if (strcmp(o->name, name) == 0) return 1;
}
return 0;
} Try / catch
// Check getopt return value for '?'
int c;
while ((c = getopt_long(argc, argv, optstring, longopts, NULL)) != -1) {
if (c == '?') {
fprintf(stderr, "Usage: %s [--known-options] args\n", argv[0]);
exit(EXIT_FAILURE);
}
// handle valid options...
} Prevention
- Maintain a --help text that lists all valid long options
- Set opterr to 0 and handle '?' yourself for custom error messages
- Validate option strings in wrapper scripts before invoking the tool
When it happens
Trigger: User passes `--foo` where `foo` is not the `name` field of any struct option in longopts. In getopt_long_only mode, also fires when the token isn't a valid short option either (my_index returns NULL). Requires opterr != 0.
Common situations: Typo in a long option name (e.g. `--verison` for `--version`); using an option from a newer/older tool version where it was renamed or removed; copy-pasting a command from docs for a different build.
Related errors
- %s: unrecognized option `%c%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/942ba314f4943d5e.
Report an issue: GitHub.