如何编译C99模式下一个C项目?
问题描述:
我得到了以下错误消息在编译C code:
I got the following error message while compiling the C code:
error: 'for' loop initial declarations are only allowed in C99 mode
note: use option -std=c99 or -std=gnu99 to compile your code
这是什么意思?
What does it mean?
如何解决?
答
您已经这样做了:
for (int i=0;i<10;i++) {
和你需要把它改成这样:
And you need to change it to this:
int i;
for (i=0;i<10;i++) {
或者,因为错误说:
使用选项-std = C99或-std = gnu99来编译code。
use option -std=c99 or -std=gnu99 to compile your code.
更新 从瑞安福克斯的答案复制的:
gcc -std=c99 foo.c -o foo
或者,如果您使用的是标准Makefile,把它添加到CFLAGS变量。
Or, if you're using a standard makefile, add it to the CFLAGS variable.