gengetopt man page

gengetopt — manual page for gengetopt 2.22.6


gengetopt [OPTIONS]...


GNU gengetopt 2.22.6

This program generates a C function that uses getopt_long function to parse the command line options, validate them and fill a struct.

-h, --help

Print help and exit


Print help, including all details and hidden options, and exit

-V, --version

Print version and exit

Main options:

-i, --input=filename

input file (default std input)

-f, --func-name=name

name of generated function (default=`cmdline_parser')

-a, --arg-struct-name=name

name of generated args info struct (default=`gengetopt_args_info')

-F, --file-name=name

name of generated file  (default=`cmdline')


output directory

if this option is not specified, the files are generated in the current directory.


header output directory


source output directory

-c, --c-extension=ext

extension of c file  (default=`c')

-H, --header-extension=ext

extension of header file  (default=`h')

-l, --long-help

long usage line in help

The usage line will print all the options, e.g.,

sample1 -iINT|--int-opt=INT [-h|--help]


by default, an option is considered optional if not specified otherwise

-u, --unamed-opts[=STRING]

accept options without names (e.g., file names) (default=`FILES')

The parser generated is thought to be used to parse the command line arguments. However, you can also generate parsers for configuration files, or strings that contain the arguments to parse, by using the following two options.

-C, --conf-parser

generate a config file parser

-S, --string-parser

generate a string parser (the string contains the command line)

Additional options

-G, --include-getopt

adds the code for getopt_long in the generated C file

-n, --no-handle-help

do not handle --help|-h automatically

If --no-handle-help is specified, the command line option --help|-h will not be handled automatically, so the programmer will be able to print some other information; then the function for printing the standard help output can be used; this function is called <parser-name>_print_help.

Notice that, although the programmer can handle --help|-h manually, the parser will return after finding such option: the other command line options, if any, will be ignored.  In case you want to have full control on --help|-h, you should use --ho-help.


do not add --help|-h automatically

With this option you can disable the automatic addition of options --help|-h. The programmer will then be able to add this option in the input file and handle it as he sees fit.  Notice that --no-help will also disable the automatic options --detailed-help and --full-help.

The programmer can still define options with short character h as he wants, but he cannot define options help, unless he specifies --no-help (otherwise an error will be printed).

-N, --no-handle-version

do not handle --version|-V automatically


do not add --version|-V automatically

See above the details about --no-handle-help and --no-help, respectively.

-e, --no-handle-error

do not exit on errors

With this option, if the generated parser encounters an error (e.g., an unknown option) it does not make the main program exit; instead, the parser function returns a value different 0, and the main program can print a help message.


in the output of help will specify which options are mandatory, by using the optional passed string  (default=`(mandatory)')


completely hide hidden options

-g, --gen-version

put gengetopt version in the generated file (default=on)


set the package name (override package defined in the .ggo file)


set the version number (override version defined in the .ggo file)


show the output of --help instead of generating code


show the output of --full-help (i.e., including hidden options) instead of generating code


show the output of --detailed-help (i.e., including details and hidden options) instead of generating code


show the output of --version instead of generating code

Please refer to the info manual for further explanations.

Maintained by Lorenzo Bettini <>

See Also

The full documentation for gengetopt is maintained as a Texinfo manual.  If the info and gengetopt programs are properly installed at your site, the command

info gengetopt

should give you access to the complete manual.


November 2012 gengetopt 2.22.6 User Commands