【问题标题】:What type of error is this in C++? [duplicate]这在 C++ 中是什么类型的错误? [复制]
【发布时间】:2018-08-26 06:10:28
【问题描述】:

编译我的 .cpp 文件时遇到问题。编译器给了我很多错误行,它的一个 sn-p 如下所示。 (没有全部显示,因为有很多像这样的错误行)

这可能指的是哪种错误?

/tmp/ccl9wLjI.o: In function `bool __gnu_cxx::__ops::_Iter_equal_to_iter::operator()<__gnu_cxx::__normal_iterator<Point2D*, std::vector<Point2D, std::allocator<Point2D> > >, __gnu_cxx::__normal_iterator<Point2D*, std::vector<Point2D, std::allocator<Point2D> > > >(__gnu_cxx::__normal_iterator<Point2D*, std::vector<Point2D, std::allocator<Point2D> > >, __gnu_cxx::__normal_iterator<Point2D*, std::vector<Point2D, std::allocator<Point2D> > >) const':
Main.cpp:(.text._ZNK9__gnu_cxx5__ops19_Iter_equal_to_iterclINS_17__normal_iteratorIP7Point2DSt6vectorIS4_SaIS4_EEEES9_EEbT_T0_[_ZNK9__gnu_cxx5__ops19_Iter_equal_to_iterclINS_17__normal_iteratorIP7Point2DSt6vectorIS4_SaIS4_EEEES9_EEbT_T0_]+0x2d): undefined reference to `operator==(Point2D&, Point2D&)'
/tmp/ccl9wLjI.o: In function `bool __gnu_cxx::__ops::_Iter_equal_to_iter::operator()<__gnu_cxx::__normal_iterator<Point3D*, std::vector<Point3D, std::allocator<Point3D> > >, __gnu_cxx::__normal_iterator<Point3D*, std::vector<Point3D, std::allocator<Point3D> > > >(__gnu_cxx::__normal_iterator<Point3D*, std::vector<Point3D, std::allocator<Point3D> > >, __gnu_cxx::__normal_iterator<Point3D*, std::vector<Point3D, std::allocator<Point3D> > >) const':

请指教。

【问题讨论】:

  • 这是链接器错误,而不是语言错误。 operator== 已声明但在链接阶段未找到。
  • 你应该显示一些minimal reproducible example 或者至少你的整个编译命令。链接步骤中可能缺少一些 *.o 目标文件

标签: c++ compiler-errors compilation


【解决方案1】:

首先,我会建议你read this,并尽可能地关注它。特别是关于这篇文章,read here

似乎您使用的是std::vector&lt;Point2D&gt;(还有一个用于Point3d)但是链接器(不是编译器——你的代码编译没有错误) 无法解析(即找到)您的 定义 此类运算符 ==(即 Point2d)。

要解决此链接器错误,请阅读并遵循以下内容:What is an undefined reference/unresolved external symbol error and how do I fix it?

【讨论】:

  • 前两个看起来最好作为评论,最后一个链接最好将此问题标记为重复
  • @AlanBirtles 感谢您的反馈!我一定会考虑到这一点。
  • @AlanBirtles 我对此的 2 美分将是这个问题既没有标题也没有被问到作为我提出进一步参考的问题。所以不是重复的。至少如果谓词“重复”意味着问题及其重复项需要从 OP 的角度“看起来”相同——至于这个 OP 甚至不知道这是一个链接器错误,因此这里的问题此帖子与链接的帖子不同。
  • @AlanBirtles 如果没有额外的信息表明他遇到的实际上是链接器错误,那么严格地将她/他提到另一个问题对他来说毫无意义。
  • @AlanBirtles 我猜你觉得投反对票是对的——但如果这是他的问题的一个很好的答案——在操作系统的其他地方找不到——那么你就是惩罚这个答案不是因为它是一个坏答案。很确定这不是投票机制的用途。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-18
  • 2019-01-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多