Getopt not included? implicit declaration of function ‘getopt’

Try removing the -std=c99. This prevents the POSIX macros from being defined in <features.h>, which prevents <unistd.h> from including <getopt.h>. Or include getopt.h yourself.


Add #include <getopt.h> among the includes.


You cloud not remove -std=c99. Instead, add #define _POSIX_C_SOURCE 2 at beginning.


There is absolute no need to change the -std or to include getopt.h directly.

The right thing to do if you want to use the C99 (or any other standardized) language features together with POSIX functions (like getopt) is to define _POSIX_C_SOURCE to the right version (e.g., 200809L) before including the respective headers. For more details see feature_test_macros(7).

Tags:

Linux

C

Getopt