Lisa
Lisa

Reputation: 601

Undefined symbols. ld: symbol not found

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

Upvotes: 4

Views: 26139

Answers (5)

Mike Seymour
Mike Seymour

Reputation: 254461

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.

Upvotes: 12

Gal Goldman
Gal Goldman

Reputation: 8869

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.

Upvotes: 1

user50049
user50049

Reputation:

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 :)

Upvotes: 0

Mike Dunlavey
Mike Dunlavey

Reputation: 40669

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

Upvotes: 0

Jack
Jack

Reputation: 133577

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

Upvotes: 1

Related Questions