I try to build a function for parsing cmd line. But, when I define the long_options
array I get the compile errors:
error: array type has incomplete element type
error: field name not in record or union initializer
error: (near initialization for 'long_options')
// and so on for every defined line in the 'long_options'
The code:
//parse_cmd.c
void parse_cmd(int argc, char *argv[]) {
while (1) {
int input_char;
static struct option long_options[] = {
{.name = "dev-name", .has_arg = 1, .val = 'd'},
{.name = "tcp-port", .has_arg = 1, .val = 't'},
{.name = "ib-port", .has_arg = 1, .val = 'i'},
{.name = "seed", .has_arg = 1, .val = 's'},
{.name = "iters", .has_arg = 1, .val = 'I'},
{.name = "mask", .has_arg = 1, .val = 'm'},
{.name = NULL, .has_arg = 0, .val = '\0'}
};
}
}
Can you please help why I get these errors?
Make sure you do:
#include <getopt.h>
in the beginning of the C file, to pull in the getopt()
function prototyp and its related declarations, including struct option
.