不能在 Ubuntu 12.10 上包含没有错误的"linux/in6.h"

Can not include "linux/in6.h" without errors on Ubuntu 12.10

本文关键字:linux in6 有错误 包含没 Ubuntu 不能      更新时间:2023-10-16

我不能包括linux/in6.h头到我的源代码没有得到这些重定义错误:

In file included from mypmtud.cc:30:0: /usr/include/linux/in6.h:30:8: error: redefinition of ‘struct in6_addr’ In file included from /usr/include/netdb.h:28:0,
             from mypmtud.cc:23: /usr/include/netinet/in.h:198:8: error: previous definition of ‘struct in6_addr’ In file included from mypmtud.cc:30:0: /usr/include/linux/in6.h:46:8: error: redefinition of ‘struct sockaddr_in6’ In file included from /usr/include/netdb.h:28:0,
             from mypmtud.cc:23: /usr/include/netinet/in.h:239:8: error: previous definition of ‘struct sockaddr_in6’ In file included from mypmtud.cc:30:0: /usr/include/linux/in6.h:54:8: error: redefinition of ‘struct ipv6_mreq’ In file included from /usr/include/netdb.h:28:0,
             from mypmtud.cc:23: /usr/include/netinet/in.h:275:8: error: previous definition of ‘struct ipv6_mreq’ make: *** [mypmtud] Error 1

我如何将linux/in6.h文件包含到我的代码中?我需要linux/in6.h来定义IPV6_DONTFRAGsetsockopt()来理解这个选项。我所包含的所有其他头文件:

#include <iostream>
#include <fstream>
#include <string>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <sstream>
#include <ctype.h>
#include <signal.h>
#include <map>
#include <errno.h>
#include <sys/time.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/ip_icmp.h>

我在VirtualBox 4.2.6上运行Ubuntu 12.10

看起来linux/in6.hnetdb.h有名称冲突。如果您可以发现netdb.h中需要的所有名称都在linux/in6.h中,则可以将其删除,这样就可以了。而且,再读一遍让我觉得它可能已经包含在netinet/in.h中了。

编辑:

(摘自下面的评论:)让我为您分解错误信息:/usr/include/linux/in6.h:30:8: error: redefinition of ‘struct in6_addr’ In file included from /usr/include/netdb.h:28:0即。'struct in6_addr'已在netdb.h中定义。接下来netinet/in.h还提供了导致另一个冲突的结构体。之后的一切都是关于在netinet/in6.h和netdb.h中先前定义的结构体,同时试图包括netinet/in.h。使用netdb.hlinux/in6.h的代码部分是分开的吗?如果是,请尝试不同的文件。我认为对于不同的文件,您可能拥有的任何冲突都将被删除,因为每个文件都是一种名称空间(我正在考虑python上下文中的名称空间)。我不是百分百确定,但我稍后会检查。