免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 7680 | 回复: 3
打印 上一主题 下一主题

包含netinet/in.h和sys/socket.h编译会出错? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2003-05-26 17:03 |只看该作者 |倒序浏览
程序简单:
//----------test.c---------
#include <sys/socket.h>;
main()
{
    return 0;
}
//-------------------------
gcc -o test test.c编译出错如下:
/usr/include/sys/socket.h:52: syntax error before `sa_family_t'
/usr/include/sys/socket.h:52: warning: data definition has no type or storag
e class
/usr/include/sys/socket.h:163: syntax error before `u_char'
/usr/include/sys/socket.h:174: syntax error before `u_short'
/usr/include/sys/socket.h:188: syntax error before `u_char'
<下面的错误消息省略>;
  
  

  
又有如果include了<netinet/in.h>;
就会出现下面的错误:
/usr/include/netinet/in.h:233: syntax error before `in_addr_t'
/usr/include/netinet/in.h:285: syntax error before `u_char'
In file included from /usr/include/netinet/in.h:475,
                 from test.c:1:
/usr/include/netinet6/in6.h:122: syntax error before `u_int8_t'
/usr/include/netinet6/in6.h:144: syntax error before `u_int8_t'
/usr/include/netinet6/in6.h:149: syntax error before `u_int32_t'
/usr/include/netinet6/in6.h:606: syntax error before `struct'
<下面还有的错误省略>;
  
请问这是为什么呢?我用FreeBSD5.0Release. 注:在LINUX下是没有出错的.

论坛徽章:
0
2 [报告]
发表于 2003-05-26 18:23 |只看该作者

包含netinet/in.h和sys/socket.h编译会出错?

...

#include <sys/type.h>;
#include <sys/socket.h>;


...

#include <sys/type.h>;
#include <netinet/in.h>;

论坛徽章:
0
3 [报告]
发表于 2003-05-26 18:33 |只看该作者

包含netinet/in.h和sys/socket.h编译会出错?

OH, THX,
是加上
#include <sys/types.h>;
就行了,
但是为什么在Linux下就不用呢?

论坛徽章:
0
4 [报告]
发表于 2003-05-26 18:47 |只看该作者

包含netinet/in.h和sys/socket.h编译会出错?

...

不太清楚 linux 在什么地方定义了,在 BSD 中是这样说的

/*
*      POSIX Standard: 2.6 Primitive System Data Types <sys/types.h>;
*/

根据POSIX标准,老的UNIX系统都需要加上
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP