【问题标题】:Can not include "linux/in6.h" without errors on Ubuntu 12.10在 Ubuntu 12.10 上不能无错误地包含“linux/in6.h”
【发布时间】:2012-12-21 13:18:59
【问题描述】:

我无法将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。

【问题讨论】:

  • 我可能读错了错误输出,但似乎in.h 为您包括in6.h。在这种情况下,您不应该已经有IPV6_DONTFRAG 可用吗?通常,您实际上不需要包含特定于系统的标头。 (除非该选项是非标准的。)
  • 可能提供您为此使用的实际gcc 命令可能是个好主意...
  • @millimoose:IPV6_DONTFRAG 未在 in.h 中定义。我可以用#ifndef IPV6_DONTFRAG #define IPV6_DONTFRAG 62 #endif 定义它,但我不确定这是否是一个好的解决方案。 @user1849534:g++ -std=c++0x -Wall -g -pedantic -W -DDEBUG -lresolv

标签: c++ linux ubuntu ipv6 ipv4


【解决方案1】:

看起来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 中定义。 Next netinet/in.h 还提供了导致另一个冲突的结构。之后的一切都是关于之前在netinet/in6.h 和netdb.h 中定义的结构,同时试图包含netinet/in.h。使用netdb.hlinux/in6.h 的代码部分是否分开?如果是这样,请尝试不同的文件。我认为对于不同的文件,您可能遇到的任何冲突都将被删除,因为每个文件都是一种命名空间(我正在考虑 python 上下文中的命名空间)。我不能 100% 确定这一点,但我稍后会检查。

【讨论】:

  • 我无法删除netdb.h,因为它包含的定义和功能比linux/in6.h 多。不定义 IPV6_DONTFRAG 我自己或包括 linux/in6.h 我得到 IPV6_NOTFRAG not defined in this scope
  • 那么让我为您分解错误消息:/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 中定义。 Next netinet/in.h 还提供了导致另一个冲突的结构。之后的一切都是关于之前在netinet/in6.hnetdb.h 中定义的结构,同时试图包含netinet/in.h。使用netdblinux/in6 的代码部分是分开的吗?如果是这样,请尝试不同的文件。我将编辑我的评论。
猜你喜欢
  • 2013-01-03
  • 1970-01-01
  • 1970-01-01
  • 2013-10-10
  • 1970-01-01
  • 2012-09-30
  • 2020-12-17
  • 2013-01-06
  • 1970-01-01
相关资源
最近更新 更多