1. 现象描述
    今天在编译tree-2.0.2的源码时报错如下:
    tree.c:668:3: error: ‘for’ loop initial declarations are only allowed in C99 mode
    for(int i=0; i < ipattern; i++)
    ^
    tree.c:668:3: note: use option -std=c99 or -std=gnu99 to compile your code
[root@k8s-master tree-2.0.2]# make
gcc -O3 -pedantic -Wall -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -c -o tree.o tree.c
In file included from tree.c:20:0:
tree.h:63:1: warning: C++ style comments are not allowed in ISO C90 [enabled by default]// Start using PATH_MAX instead of the magic number 4096 everywhere.^
tree.h:63:1: warning: (this will be reported only once per input file) [enabled by default]
tree.c:47:1: warning: C++ style comments are not allowed in ISO C90 [enabled by default]//off_t (*listdir)(char *, int *, int *, u_long, dev_t) = unix_listdir;^
tree.c:47:1: warning: (this will be reported only once per input file) [enabled by default]
tree.c: In function ‘main’:
tree.c:100:3: warning: ISO C90 forbids mixed declarations and code [-Wpedantic]bool needfulltree;^
tree.c:124:29: warning: ISO C90 forbids compound literals [-Wpedantic]lc = (struct listingcalls){^
tree.c:138:3: warning: ISO C90 forbids mixed declarations and code [-Wpedantic]char *stddata_fd = getenv(ENV_STDDATA_FD);^
tree.c:145:33: warning: ISO C90 forbids compound literals [-Wpedantic]lc = (struct listingcalls){^
tree.c:263:30: warning: ISO C90 forbids compound literals [-Wpedantic]lc = (struct listingcalls){^
tree.c:271:30: warning: ISO C90 forbids compound literals [-Wpedantic]lc = (struct listingcalls){^
tree.c:279:30: warning: ISO C90 forbids compound literals [-Wpedantic]lc = (struct listingcalls){^
tree.c: In function ‘usage’:
tree.c:659:2: warning: string length ‘3348’ is greater than the length ‘509’ ISO C90 compilers are required to support [-Woverlength-strings]"  --            Options processing terminator.\n");^
tree.c: In function ‘patignore’:
tree.c:668:3: error: ‘for’ loop initial declarations are only allowed in C99 modefor(int i=0; i < ipattern; i++)^
tree.c:668:3: note: use option -std=c99 or -std=gnu99 to compile your code
tree.c: In function ‘patinclude’:
tree.c:679:3: error: ‘for’ loop initial declarations are only allowed in C99 modefor(int i=0; i < pattern; i++)^
tree.c: In function ‘getinfo’:
tree.c:712:3: warning: ISO C90 forbids mixed declarations and code [-Wpedantic]int isdir = (st.st_mode & S_IFMT) == S_IFDIR;^
tree.c: In function ‘do_date’:
tree.c:1279:7: warning: ISO C90 does not support the ‘%e’ gnu_strftime format [-Wformat=]strftime(buf,255,"%b %e  %Y",tm);^
tree.c:1281:7: warning: ISO C90 does not support the ‘%e’ gnu_strftime format [-Wformat=]strftime(buf,255,"%b %e %R", tm);^
tree.c:1281:7: warning: ISO C90 does not support the ‘%R’ gnu_strftime format [-Wformat=]
tree.c: In function ‘printit’:
tree.c:1304:2: warning: ISO C90 does not support the ‘%lc’ gnu_printf format [-Wformat=]if (iswprint(*tp)) fprintf(outfile,"%lc",(wint_t)*tp);^
tree.c: In function ‘psize’:
tree.c:1351:59: warning: ISO C90 does not support ‘long long’ [-Wlong-long]} else return sprintf(buf, sizeof(off_t) == sizeof(long long)? " %11lld" : " %9lld", (long long int)size);^
tree.c:1351:94: warning: ISO C90 does not support ‘long long’ [-Wlong-long]} else return sprintf(buf, sizeof(off_t) == sizeof(long long)? " %11lld" : " %9lld", (long long int)size);^
tree.c:1351:3: warning: ISO C90 does not support the ‘ll’ gnu_printf length modifier [-Wformat=]} else return sprintf(buf, sizeof(off_t) == sizeof(long long)? " %11lld" : " %9lld", (long long int)size);^
tree.c: In function ‘fillinfo’:
tree.c:1398:50: warning: ISO C90 does not support ‘long long’ [-Wlong-long]if (inodeflag) n += sprintf(buf," %7lld",(long long)ent->linode);^
tree.c:1398:3: warning: ISO C90 does not support the ‘ll’ gnu_printf length modifier [-Wformat=]if (inodeflag) n += sprintf(buf," %7lld",(long long)ent->linode);^
make: *** [tree.o] Error 1
  1. 原因分析
    gcc默认采用的C89编译器,C89不支持在for循环中初始化增量。
  2. 解决方案
    将Makefile文件中的CC=gcc改为CC=gcc -std=c99,重新make即可。
[root@k8s-master tree-2.0.2]# make
gcc -std=c99 -O3 -pedantic -Wall -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -c -o tree.o tree.c
gcc -std=c99 -O3 -pedantic -Wall -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -c -o list.o list.c
gcc -std=c99 -O3 -pedantic -Wall -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -c -o hash.o hash.c
gcc -std=c99 -O3 -pedantic -Wall -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -c -o color.o color.c
gcc -std=c99 -O3 -pedantic -Wall -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -c -o file.o file.c
gcc -std=c99 -O3 -pedantic -Wall -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -c -o filter.o filter.c
gcc -std=c99 -O3 -pedantic -Wall -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -c -o info.o info.c
gcc -std=c99 -O3 -pedantic -Wall -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -c -o unix.o unix.c
gcc -std=c99 -O3 -pedantic -Wall -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -c -o xml.o xml.c
gcc -std=c99 -O3 -pedantic -Wall -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -c -o json.o json.c
gcc -std=c99 -O3 -pedantic -Wall -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -c -o html.o html.c
gcc -std=c99 -O3 -pedantic -Wall -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -c -o strverscmp.o strverscmp.c
gcc -std=c99 -s -o tree tree.o list.o hash.o color.o file.o filter.o info.o unix.o xml.o json.o html.o strverscmp.o

make编译源码时报error: ‘for’ loop initial declarations are only allowed in C99 mode的解决办法相关推荐

  1. error: 'for' loop initial declarations are only allowed in C99 mode

    使用gcc编译代码是报出 error: 'for' loop initial declarations are only allowed in C99 mode note: use option -s ...

  2. error: 'for' loop initial declarations are only allowed in C99 or C11 mode

    code::blocks编译排序算法时,报错 error: 'for' loop initial declarations are only allowed in C99 or C11 mode 查询 ...

  3. error: ‘for’ loop initial declarations are only allowed in C99 mode

    在使用gcc编译代码时出现如下报错: error: 'for' loop initial declarations are only allowed in C99 mode note: use opt ...

  4. 【经验分享】Error:‘for’ loop initial declarations are only allowed in C99 mode 的解决方案

    现象   今天在使用 gcc 编译代码时报出: error: 'for' loop initial declarations are only allowed in C99 modenote: use ...

  5. [Error] ‘for‘ loop initial declarations are only allowed in C99 mode

    [Error] 'for' loop initial declarations are only allowed in C99 mode for对i声明定义放在外面定义即可. 或者是在工具(tool) ...

  6. [Error] ‘for‘ loop initial declarations are only allowed in C99 or C11 mode 问题解决

    在for和if语句中把初始化的变量移出来,得先定义才行,因为devc++中只允许C99与C11标准

  7. 解决 ‘for‘ loop initial declarations are only allowed in C99 mode

    解决 'for' loop initial declarations are only allowed in C99 mode) 这个报错的的意思就是:只允许在C99模式下使用'for'循环初始化声明 ...

  8. 【流媒体开发】VLC Media Player - Android 平台源码编译 与 二次开发详解 (提供详细800M下载好的编译源码及eclipse可调试播放器源码下载)

    作者 : 韩曙亮  博客地址 : http://blog.csdn.net/shulianghan/article/details/42707293 转载请注明出处 : http://blog.csd ...

  9. ubuntu配置android开发环境和编译源码遇到的一些问题

    ---------------------------------------------环境变量设置--------------------------------------------- 1.设 ...

  10. ubuntu中手动编译源码安装Xorg-server过程中依赖关系的解决

    ubuntu中手动编译源码安装Xorg-server过程中依赖关系的解决 在linux系统中手动编译源码安装软件包的过程是非常痛苦的,然而这一个多星期以来我是强忍住脾气体验了一把,虽然面对慢的令人发指 ...

最新文章

  1. python中的类的成员变量以及property函数
  2. 分布式系统理论之两阶段提交协议
  3. [deviceone开发]-日程日历示例
  4. php 编写mysql_php编写数据写入mysql问题
  5. vc6项目-vc8项目 转换日志
  6. 这个东西可以温暖你想打BUG的心......
  7. 人生三分之一的睡眠决定着另外三分之二的精彩
  8. 【前端性能】必须要掌握的原生JS实现JQuery
  9. 检测磁盘smartmontools
  10. 暂停按钮_年报巨亏400多亿,国内钾肥龙头启动暂停上市按钮
  11. [转] 串、并行加法器
  12. 空间坐标系(惯性坐标系、地球坐标系、WGS-84坐标系、站心坐标系)
  13. 【136天】尚学堂高淇Java300集视频精华笔记(77-78)
  14. 华为网络设备加固各种基线命令配置
  15. 微信好友大揭秘,使用Python抓取朋友圈数据,通过人脸识别全面分析好友,一起看透你的“朋友圈”
  16. thinkpad t440安装os小记
  17. 全景分割相关论文写作与准备笔记
  18. 我手机上常用的app和常访问的网站
  19. gitlab rpm包安装方法
  20. 【Xasset谷歌分包】打包AAB并上传谷歌商店操作流程分享

热门文章

  1. Presto架构和使用总结
  2. 好用的组件Vue Tags Input 输入框标签
  3. 是什么撑起了极兔快递近200亿美元的估值?
  4. IBM Spectrum LSF-手册
  5. U盘无法打开的解决方法大全
  6. android 手机如何截屏,安卓手机一般怎么截屏 安卓如何截图手机屏幕 - 云骑士一键重装系统...
  7. 减肥日志:100天40斤!!
  8. Python基础概要(一天快速入门)
  9. 今天不忙,咱们来说说域名是什么意思?
  10. java pack unpack_解释一下pack和unpack