You compile with -ansi , and getopt may not be available in this mode, since -ansi implies C89 compliance mode. Try removing this switch or #define _GNU_SOURCE to #include <unistd.h> . getopt() is POSIX, not ANSI.
Edit: you probably don't need _GNU_SOURCE . According to this , you should be able to get functionality with macro definition of the preprocessor so that this is true:
#if _POSIX_C_SOURCE >= 2 || _XOPEN_SOURCE || _POSIX_SOURCE
For more information on function verification macros, see.
Alok singhal
source share