未定义的符号. ld:找不到符号 [英] Undefined symbols. ld: symbol not found

查看:221
本文介绍了未定义的符号. ld:找不到符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

除此未定义的符号错误外,所有其他东西都在起作用:

Everything is working except this undefined symbols error:

bash-3.2$ make
g++ -Wall -g solvePlanningProblem.o Position.o AStarNode.o PRM.o PRMNode.o Worl.o SingleCircleWorld.o Myworld.o RECTANGLE.o CIRCLE.o -o solvePlanningProblem

`Undefined symbols:
  "Obstacle::~Obstacle()", referenced from:
      Myworld::~Myworld()in Myworld.o
      Myworld::~Myworld()in Myworld.o
      Myworld::~Myworld()in Myworld.o
  "RECTANGLE::RECTANGLE()", referenced from:
      Myworld::readObstacles(std::basic_istream<char, std::char_traits<char> >&
in Myworld.o
  "CIRCLE::CIRCLE()", referenced from:
      Myworld::readObstacles(std::basic_istream<char, std::char_traits<char> >&
in Myworld.o
  "typeinfo for Obstacle", referenced from:
      typeinfo for RECTANGLEin RECTANGLE.o
      typeinfo for CIRCLEin CIRCLE.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make: *** [solvePlanningProblem] Error 1`

这是一个奇怪的错误.构造函数或析构函数有问题吗? 任何建议都会有所帮助.

It's such a strange error. Is something wrong with the constructor or destructor? Any advice will help.

在所有构造函数和析构函数之后添加{}后,错误已减少 到:

After adding {} after all constructors and destructors the error has been reduced to:

Undefined symbols:

  "vtable for Obstacle", referenced from:
      Obstacle::Obstacle()in Myworld.o
  "typeinfo for Obstacle", referenced from:
      typeinfo for RECTANGLEin RECTANGLE.o
      typeinfo for CIRCLEin CIRCLE.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

推荐答案

链接器找不到Obstacle类的析构函数.

The linker can't find the destructor for the Obstacle class.

它在另一个目标文件中(也许是Obstacle.o)吗?如果是这样,请将其添加到要链接的对象列表中.

Is it in another object file (perhaps Obstacle.o)? If so, add that to the list of objects to link.

在类定义中是否应该是一个空的虚拟析构函数?在这种情况下,请确保您已写

Is it supposed to be an empty virtual destructor within the class definition? In that case, make sure you've written

virtual ~Obstacle() {}

不是

virtual ~Obstacle();

第一个实现析构函数;第二个声明它存在,但是在其他地方实现.

The first implements the destructor; the second declares that it exists, but is implemented somewhere else.

这篇关于未定义的符号. ld:找不到符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆