eclipse 写c bug 解决笔记


一、


Eclipse CDT 解决 "for loop initial declaration used outside C99 mode" 错误
在用 Eclipse CDT 编写c程序时出现 `for' loop initial declaration used outside C99 mode 错误是因为加 -std=c99 选项


C99标准支持下面这种for 循环的变量i的定义及初始化方式:
for (int var = 0; var < 10; ++var) {
}


C99标准之外的C标准支持下面这种for 循环的变量i的定义及初始化方式:
int var;
for (var = 0; var < 10; ++var) {


}






解决办法:


右键点击项目->Properties->C/C++ Build -> Settings -> Tool Settings -> GCC C Complier -> Miscellaneous


在 "Other flags" 中追加 -std=c99




二、
/usr/include/pcap/bpf.h:88:1: error: unknown type name ‘u_int’
 /usr/include/pcap/bpf.h:108:2: error: unknown type name ‘u_int’
 /usr/include/pcap/bpf.h:1260:2: error: unknown type name ‘u_short’
 /usr/include/pcap/bpf.h:1261:2: error: unknown type name ‘u_char’
 /usr/include/pcap/bpf.h:1262:2: error: unknown type name ‘u_char’
 In file included from ../src/test.c:1:0:
 /usr/include/pcap/pcap.h:125:2: error: unknown type name ‘u_short’
 /usr/include/pcap/pcap.h:126:2: error: unknown type name ‘u_short’
 /usr/include/pcap/pcap.h:171:2: error: unknown type name ‘u_int’




http://stackoverflow.com/questions/15393905/c-pcap-library-unknown-types-error


解决方法:


Actually, yes, you did define at least one of them, by specifying -std=c99. The GCC man page says -std= has the same effect as -ansi, and -ansi defines __STRICT_ANSI__. -std=c99 may define _ISOC99_SOURCE as well as, or instead of, __STRICT_ANSI__. -std=c99 means you want your code to be compiled as strict ISO C99, meaning it can't use any features not in ISO C99 - and libpcap isn't in ISO C99, so.... If you're trying to use C99 features and they're not supported by default, try -std=gnu99.


其实就是  类似于二中的解决方案    添加-std=gnu99




三、


unknown type name 'socklen_t'


解决方法:  加上 #include "WS2tcpip.h"


四、 
如果 while(true)报错
改成while (1) 就可以了
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值