【问题标题】:Error including netinet/in.h包括 netinet/in.h 在内的错误
【发布时间】:2014-02-18 00:10:07
【问题描述】:

即使尝试了所有头文件包含的顺序, 我仍然收到 netinet/in.h 的错误

/usr/include/netinet/in.h:34: error: expected identifier before numeric constant

我已经包含了以下头文件

#include <sys/ioctl.h>
#include <sys/socket.h>
#include <net/if.h>
#include <linux/if_tun.h>
#include <sys/select.h>
#include <fcntl.h>
#include <sys/types.h>
#include <errno.h>
#include <netinet/ip.h>
#include <netinet/in.h>

如何消除此错误? 我用 gcc -g3 -Wall 编译。

【问题讨论】:

  • netinet/in.h 尝试定义IPPROTO_IP,它已经在您的代码中由netinet/ip.h 定义。如果您切换这 2 个包含的顺序,那应该可以工作。

标签: c gcc


【解决方案1】:

netinet/in.h 没有标头保护,所以发生的情况是 netinet/ip.h 标头文件中已经定义了一些变量。尝试将 netinet/in.h 推到文件的开头。

【讨论】:

    猜你喜欢
    • 2020-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-27
    • 1970-01-01
    • 2018-03-11
    • 2016-09-05
    • 1970-01-01
    相关资源
    最近更新 更多