This is the mail archive of the
cygwin@cygwin.com
mailing list for the Cygwin project.
Win32Api getopts: -mno-cygwin: optind undefined
- From: Gerald Reno <grenoml at yahoo dot com>
- To: cygwin at cygwin dot com
- Date: Sat, 6 Jul 2002 21:14:23 -0700 (PDT)
- Subject: Win32Api getopts: -mno-cygwin: optind undefined
Is it possible to link with win32api and still use
getopts? When I attempt this I get undefined
reference for optind, optarg, etc. But all is well if
I remove -mno-cygwin. Do I need to link with a
separate lib?
g++ test.c -ansi -mno-cygwin -o test.exe NOT OK
g++ test.c -ansi -o test.exe OK
----------------------------------------
// test.c
#include <stdio.h>
#include <unistd.h>
int getopt(int argc, char * const argv[],
const char *optstring);
extern char *optarg;
extern int optind, opterr, optopt;
int
main (int argc, char **argv)
{
int c;
int digit_optind = 0;
while (1)
{
int this_option_optind = optind ? optind :
1;
int option_index = 0;
c = getopt (argc, argv, "abc:d:012");
if (c == -1)
break;
switch (c)
{
case 0:
// printf ("option %s",
long_options[option_index].name);
if (optarg)
printf (" with arg %s", optarg);
printf ("\n");
break;
case '0':
case '1':
case '2':
if (digit_optind != 0 && digit_optind !=
this_option_optind)
printf ("digits occur in two different
argv-elements.\n");
digit_optind = this_option_optind;
printf ("option %c\n", c);
break;
case 'a':
printf ("option a\n");
break;
case 'b':
printf ("option b\n");
break;
case 'c':
printf ("option c with value `%s'\n",
optarg);
break;
case 'd':
printf ("option d with value `%s'\n",
optarg);
break;
case '?':
break;
default:
printf ("?? getopt returned character
code 0%o ??\n", c);
}
}
if (optind < argc)
{
printf ("non-option ARGV-elements: ");
while (optind < argc)
printf ("%s ", argv[optind++]);
printf ("\n");
}
exit (0);
}
__________________________________________________
Do You Yahoo!?
Sign up for SBC Yahoo! Dial - First Month Free
http://sbc.yahoo.com
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/