I have these headers in a c code
#include <stdio.h>
#include <unistd.h>
Everything compiled fine until I added -std=c99 flag to gcc command (to enable restrict). And this triggered the following errors.
warning: implicit declaration of function
fileno
error:
F_LOCK
undeclared (first use in this function)
error: (Each undeclared identifier is reported only once error: for each function it appears in.)
error:F_ULOCK
undeclared (first use in this function
Any ideas to workaround these errors/warnings?
You need to tell the headers that you want the POSIX extensions. These days, I use:
#if __STDC_VERSION__ >= 199901L
#define _XOPEN_SOURCE 600
#else
#define _XOPEN_SOURCE 500
#endif /* __STDC_VERSION__ */
If I'm compiling with -std=c89
, it gives the correct POSIX version; if you compile with -std=c89
, it gives the correct POSIX version. I use this on Solaris 9 and 10, MacOS X (10.4.x, 10.5.x), HP-UX 11.x, Linux (RHEL4 and 5, SuSE 9 and 10) and AIX 5.x and 6.x - AFAICR, without problems so far.
This stanza should appear before any system headers are included (in your own header, or in each source file), or you need to achieve the same effect with -D_XOPEN_SOURCE=600
on the compiler command line, or some other similar mechanism.
Try
-std=gnu99
to enable all extensions and still use the C99 language enhancements.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With