C++ 不能包括;linux/in6.h“;在Ubuntu 12.10上没有错误
如果没有这些重新定义错误,我无法将C++ 不能包括;linux/in6.h“;在Ubuntu 12.10上没有错误,c++,linux,ubuntu,ipv6,ipv4,C++,Linux,Ubuntu,Ipv6,Ipv4,如果没有这些重新定义错误,我无法将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/netine
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\u DONTFRAG
定义和setsockopt()
来理解此选项。
我包含的所有其他头文件:
#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上运行Ubuntu12.10。看起来像是
linux/in6.h
与netdb.h
有名称冲突。如果您可以发现您需要的netdb.h
中的所有名称都在linux/in6.h
中,那么您可以删除这些名称,这样就可以了。另外,再次阅读它让我觉得它可能已经包含在你的netinet/in.h
中了
编辑:
(来自下面的评论:)
让我为您分析一下错误消息:
/usr/include/linux/in6.h:30:8:错误:在/usr/include/netdb.h:28:0中包含的文件中重新定义“struct in6_addr”,即netdb.h中已经定义了“struct in6_addr”。Nextnetinet/in.h
还提供了导致另一个冲突的结构。之后的一切都是关于在试图包含netinet/in.h
的同时,在netinet/in.h
和netdb.h中都定义了一个结构。使用netdb.h
和linux/in6.h
的代码部分是分开的吗?如果是,请尝试不同的文件。我认为,对于不同的文件,您可能遇到的任何冲突都将被消除,因为每个文件都有一种名称空间(我在python上下文中考虑名称空间)。我不是100%确定,但我稍后会检查。我可能读错了错误输出,但对您来说,in.h
includesin6.h
。在这种情况下,您不应该已经有了可用的IPV6\u DONTFRAG
?通常,您不应该真正需要包含系统特定的头。(除非该选项是非标准的。)可能提供您为此使用的实际gcc
命令是个好主意…@millimoose:IPV6\u DONTFRAG
未在in.h
中定义。我可以用#ifndef IPV6_DONTFRAG#define IPV6_DONTFRAG 62#endif
来定义它,但我不确定这是否是一个好的解决方案@user1849534:g++-std=c++0x-Wall-g-pedantic-W-DDEBUG-lresolv
我无法删除netdb.h
,因为它包含比linux/in6.h
更多的定义和函数。如果我自己没有定义IPV6,也没有包含linux/in6.h,我得到的是未在此范围内定义的IPV6。让我为您分析一下错误消息:/usr/include/linux/in6.h:30:8:错误:重新定义/usr/include/netdb.h:28:0中包含的文件中的“struct in6\u addr”in6_addr'已在netdb.h
中定义。Nextnetinet/in.h
还提供了导致另一个冲突的结构。这之后的一切都是关于在试图包含netinet/in.h
的同时,在netinet/in.h
和netdb.h
中都定义了一个结构。使用netdb
和linux/in6
的代码部分是分开的吗?如果是,请尝试不同的文件。我将用更多的内容编辑我的评论。