tags:

views:

2016

answers:

5

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
+1  A: 

Seems like you are missing the implementation of the desctructor ~Obstacle that is anyway defined..

LD is the linker, this means that everything compiles fine but when it starts to link binaries into one it can't find the destructor for Obstacle used in your code..

Add

~Obstacle() {}

to your class definition in .h file, or if you prefer just define it ~Obstacle() and provide implementation in .cpp file as ~Obstacle::Obstacle()

Jack
can you tell me how to do the destruction ?Class Obstacle is the base class with two sub-classes CIRCLE and RECTANGLE.
Lisa
Ok, you should use a virtual destruction in your base class and implement it in subclasses. Could u please edit your question and add code? that would be helpful..
Jack
I have already the ~Obstacle(); in Obstacle.h. But still the problem
Lisa
do you have it also in subclasses?
Jack
A: 

it also looks like the default constructors are missing from RECTANGLE and CIRCLE.

Mike Dunlavey
there are ~RECTANGLE and ~CIRCLE in both .h files. what do you mean by missing
Lisa
It says that `RECTANGLE::RECTANGLE` is missing. That is the constructor, not the destructor. Same for CIRCLE.
Mike Dunlavey
as said above, all constructor and deconstructor have been modified and the error has been reduced to two problems
Lisa
A: 

You are missing a library. or have a broken tool chain (which depends on the include path for gcc).

Google turned up squat.. so clarifying what you are actually trying to build lets us help you more :)

Tim Post
+1  A: 

It might be that you declared the D'tor but didn't implement it. Try to put {} in the .h file, or:

Obstacle::~Obstacle()
{
}

in the cpp.

Gal Goldman
what is the actural meaning of "typeinfo for Obstacle" and "vtable for Obstacle"
Lisa
Lisa, these messages are regarding virtualization. The vtable is referring to the "virtual table", it's a table which holds the function addresses of an object in an inheritance tree, to know to which implementation to go (because of overriding and so on).Take a look here: http://www.learncpp.com/cpp-tutorial/125-the-virtual-table/ Perhaps if you embed your code here I could be more helpful
Gal Goldman
You may have another virtual method which isn't implemented in a base class nor in its inheritants.I would go over the code and check for un-implemented methods in your classes, probably in Obstacle and its inheritants.
Gal Goldman
+3  A: 

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

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() {}

and not

virtual ~Obstacle();

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

Mike Seymour
I add {} in and the error is reduced to "typeinfo for Obstacle", referenced from: typeinfo for RECTANGLE in RECTANGLE.o typeinfo for CIRCLEin CIRCLE.o ld: symbol(s) not found collect2: ld returned 1 exit status make:
Lisa
See my answer to your other question.
Mike Seymour