gengetopt C example

Tong Sun <[email protected]> Tue, 22 Oct 2013 14:51:53 -0700 (PDT)
Newsgroups gmane.comp.gnu.gengetopt.general
Message-ID <[email protected]>
Hi again Lorenzo,=A0

I'm trying=A0gengetopt with C this time, but the C example that come with m=
y Debian/Ubuntu package gave me some errors. The first one being:

In file included from cmdline2.c:26:0:
cmdline2.h:24:35: error: expected ',' or ';' before 'PACKAGE'
=A0#define MY_CMDLINE_PARSER_PACKAGE PACKAGE

In details,=A0

Here are the example files distributed from my Debian/Ubuntu package

/usr/share/doc/gengetopt/examples
/usr/share/doc/gengetopt/examples/cmdline2.c.gz
/usr/share/doc/gengetopt/examples/cmdline2.h.gz
/usr/share/doc/gengetopt/examples/sample1.ggo
/usr/share/doc/gengetopt/examples/main1.cc
/usr/share/doc/gengetopt/examples/main2.c
/usr/share/doc/gengetopt/examples/cmdline1.c.gz
/usr/share/doc/gengetopt/examples/README.example
/usr/share/doc/gengetopt/examples/test_manual_help_cmd.c.gz
/usr/share/doc/gengetopt/examples/test_manual_help.c
/usr/share/doc/gengetopt/examples/sample2.ggo
...=A0

and my gengetopt:

$ apt-cache policy gengetopt
gengetopt:
=A0 Installed: 2.22.6-2
=A0 Candidate: 2.22.6-2
=A0 Version table:
=A0*** 2.22.6-2 0
=A0 =A0 =A0 =A0 500 http://us.archive.ubuntu.com/ubuntu/ saucy/universe i38=
6 Packages
=A0 =A0 =A0 =A0 100 /var/lib/dpkg/status


From=A0/usr/share/doc/gengetopt/examples/README.example:

...=A0

# commands to try the C example:=A0

gengetopt --input=3Dsample2.ggo --func-name=3Dmy_cmdline_parser --file-name=
=3Dcmdline2 --unamed-opts
gcc -o main2 main2.c cmdline2.c
./main2 -h
...=A0


This is how I tried:

mkdir gengetopt; cd gengetopt

=A0ln -s /usr/share/doc/gengetopt/examples/sample2.ggo
=A0ln -s /usr/share/doc/gengetopt/examples/main2.c
=A0gengetopt --input=3Dsample2.ggo --func-name=3Dmy_cmdline_parser --file-n=
ame=3Dcmdline2 --unamed-opts
=A0gcc -o main2 main2.c cmdline2.c

and here are all the errors that I get:

$ gcc -o main2 main2.c cmdline2.c
In file included from cmdline2.c:26:0:
cmdline2.h:24:35: error: expected ',' or ';' before 'PACKAGE'
=A0#define MY_CMDLINE_PARSER_PACKAGE PACKAGE
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0^
cmdline2.c:30:51: note: in expansion of macro 'MY_CMDLINE_PARSER_PACKAGE'
=A0const char *gengetopt_args_info_usage =3D "Usage: " MY_CMDLINE_PARSER_PA=
CKAGE " [
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
 =A0 =A0 =A0 =A0 =A0 =A0 =A0^
cmdline2.c: In function 'my_cmdline_parser_print_version':
cmdline2.h:32:40: error: 'PACKAGE' undeclared (first use in this function)
=A0#define MY_CMDLINE_PARSER_PACKAGE_NAME PACKAGE
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
 =A0 ^
cmdline2.c:165:14: note: in expansion of macro 'MY_CMDLINE_PARSER_PACKAGE_N=
AME'
=A0 =A0 =A0 (strlen(MY_CMDLINE_PARSER_PACKAGE_NAME) ? MY_CMDLINE_PARSER_PAC=
KAGE_NAME :
=A0 =A0 =A0 =A0 =A0 =A0 =A0 ^
cmdline2.h:32:40: note: each undeclared identifier is reported only once fo=
r each function it appears in
=A0#define MY_CMDLINE_PARSER_PACKAGE_NAME PACKAGE
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
 =A0 ^
cmdline2.c:165:14: note: in expansion of macro 'MY_CMDLINE_PARSER_PACKAGE_N=
AME'
=A0 =A0 =A0 (strlen(MY_CMDLINE_PARSER_PACKAGE_NAME) ? MY_CMDLINE_PARSER_PAC=
KAGE_NAME :
=A0 =A0 =A0 =A0 =A0 =A0 =A0 ^
cmdline2.h:38:35: error: 'VERSION' undeclared (first use in this function)
=A0#define MY_CMDLINE_PARSER_VERSION VERSION
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0^
cmdline2.c:166:6: note: in expansion of macro 'MY_CMDLINE_PARSER_VERSION'
=A0 =A0 =A0 MY_CMDLINE_PARSER_VERSION);
=A0 =A0 =A0 ^
cmdline2.c: In function 'my_cmdline_parser_dump':
cmdline2.h:24:35: error: 'PACKAGE' undeclared (first use in this function)
=A0#define MY_CMDLINE_PARSER_PACKAGE PACKAGE
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0^
cmdline2.c:293:63: note: in expansion of macro 'MY_CMDLINE_PARSER_PACKAGE'
=A0 =A0 =A0 =A0fprintf (stderr, "%s: cannot dump options to stream\n", MY_C=
MDLINE_PARSER
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0^
cmdline2.c: In function 'my_cmdline_parser_file_save':
cmdline2.h:24:35: error: 'PACKAGE' undeclared (first use in this function)
=A0#define MY_CMDLINE_PARSER_PACKAGE PACKAGE
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0^
cmdline2.c:341:66: note: in expansion of macro 'MY_CMDLINE_PARSER_PACKAGE'
=A0 =A0 =A0 =A0fprintf (stderr, "%s: cannot open file for writing: %s\n", M=
Y_CMDLINE_PAR
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ^
cmdline2.c: In function 'my_cmdline_parser_internal':
cmdline2.h:24:35: error: 'PACKAGE' undeclared (first use in this function)
=A0#define MY_CMDLINE_PARSER_PACKAGE PACKAGE
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0^
cmdline2.c:817:58: note: in expansion of macro 'MY_CMDLINE_PARSER_PACKAGE'
=A0 =A0 =A0 =A0 =A0 =A0fprintf (stderr, "%s: option unknown: %c%s\n", MY_CM=
DLINE_PARSER_PACK

Any thoughts?=A0

BTW, if you have a small working example, does it have a make file as well?=
 =A0

Thanks