Mumit Khan khan@xraylith.wisc.edu
Mon Jan 12 20:11:00 GMT 1998

Narayan Natarajan <venkman1@ix.netcom.com> writes:
> Does mingw32 have getopt in its libraries? I am having trouble compiling
> code using getopt with mingw32.

yes, and no. The GNU getopt (as well as getopt_long) is part of the 
libiberty library, which should have been in the distribution (see the
<root>/lib directory), unless I missed it somehow. Unfortunately, the
getopt.h is not installed by default, which provides the prototypes and
some of the definitions needed for getopt_long. Let me know if you can't
find it in some other GNU package and I'll email it to you.

fyi, getopt is not ANSI, hence not guaranteed to be in an ANSI-only runtime;
it is however in the POSIX.1 specs, so most real systems provide it. My 
own code uses getopt that is built along with the package, so it's not an 
issue (and that's why I didn't miss the missing getopt prototype).

As a quick hack:

  extern int getopt(int argc, char * const argv[], const char *optstring);
  extern char *optarg;
  extern int optind, opterr, optopt;

  int main (int argc, char *argv[]) {
    /* use getopt */

Now link -liberty as well.

  % cc -o getopt_test.exe getopt_test.c -liberty.

and see what happens.

For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".

More information about the Cygwin mailing list