[英]fileno, F_LOCK and F_ULOCK become undeclared and unavailable when I add std=c99 flag to gcc
I have these headers in ac code 我在交流代码中有这些标题
#include <stdio.h>
#include <unistd.h>
Everything compiled fine until I added -std=c99 flag to gcc command (to enable restrict ). 一切都编译得很好,直到我将-std = c99标志添加到gcc命令(启用限制 )。 And this triggered the following errors. 这引发了以下错误。
warning: implicit declaration of function
fileno
警告:函数fileno
隐式声明error:
F_LOCK
undeclared (first use in this function) 错误:F_LOCK
未声明(首次使用此功能)
error: (Each undeclared identifier is reported only once error: for each function it appears in.) 错误:(每个未声明的标识符仅报告一次错误:对于它出现的每个函数。)
error:F_ULOCK
undeclared (first use in this function 错误:F_ULOCK
未声明(首先在此函数中使用
Any ideas to workaround these errors/warnings? 任何解决这些错误/警告的想法?
You need to tell the headers that you want the POSIX extensions. 您需要告诉标题您想要POSIX扩展。 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; 如果我用-std=c89
编译,它会给出正确的POSIX版本; if you compile with -std=c89
, it gives the correct POSIX version. 如果使用-std=c89
编译,则会提供正确的POSIX版本。 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. 我在Solaris 9和10,MacOS X(10.4.x,10.5.x),HP-UX 11.x,Linux(RHEL4和5,SuSE 9和10)以及AIX 5.x和6.x - AFAICR上使用它,到目前为止没有问题。
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. 此节应出现在包含任何系统头之前(在您自己的头文件中或每个源文件中),或者您需要在编译器命令行或其他类似机制上使用-D_XOPEN_SOURCE=600
实现相同的效果。
Try 尝试
-std=gnu99
to enable all extensions and still use the C99 language enhancements. 启用所有扩展并仍使用C99语言增强功能。
您可以尝试-D_BSD_SOURCE启用BSD-isms或-D_SVID_SOURCE启用System-V主题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.