Linker error in Xcode

I have struggling to figure out what has been causing this linking error and it has been driving me nuts. The error that comes out of Xcode is the following:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Undefined symbols for architecture x86_64:
  "Velocity::Velocity()", referenced from:
      flyingObject::flyingObject() in rocks.o
      flyingObject::flyingObject() in bullet.o
      flyingObject::flyingObject() in ship.o
  "typeinfo for Rock", referenced from:
      typeinfo for BigRock in rocks.o
      typeinfo for MediumRock in rocks.o
      typeinfo for SmallRock in rocks.o
  "vtable for Rock", referenced from:
      Rock::Rock() in rocks.o
      Rock::Rock(Rock const&) in game.o
  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)



This is my header file that contains the only virtual function. Any help is appreciated!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#ifndef flyingObject_h
#define flyingObject_h

#include <iostream>
#include "point.h"
#include "uiDraw.h"
#include "velocity.h"

// Put your FlyingObject class here
class flyingObject : public Point
{
private:
   Velocity velocity;
   
   bool alive;
   bool wrap;
   
   int lives;
   float size;
   float spin;
   
public:
   //constructors - destructors
   flyingObject()  { alive=true; }
   ~flyingObject() { alive=false;}
   
   //getters
   Point getPoint();
   Velocity getVelocity() const {return velocity; }
   bool isAlive()         const {return alive;    }
   bool canWrap()         const {return wrap;     }
   int getLives()         const {return lives;    }
   float getSpin()        const {return spin;     }
   float getSize()        const {return size;     }
   
   //setters
   void setPoint(Point point);
   void setVelocity(Velocity v)  {this->velocity = v;  }
   void setAlive()               {this->alive = true;  }
   void setWrap()                {this->wrap =  true;  }
   void setUnwrap()              {this->wrap = false;  }
   void setLives(int lives)      {this->lives = lives; }
   void setSpin(float spin)      {this->spin = spin;   }
   void setSize(float size)      {this->size = size;   }
   void setVSpeed(float speed)   {velocity.setSpeed(speed);}
   
   //virtual
   inline virtual void draw() { }
   
   //mutators
   void advance();
   void fire(Point point, float angle, float speed);
   void rotate(float rotate, bool dir);
   void move(bool dir);
   void dowrap(Point t1, Point t2);
   
   void kill() { alive = false; }
};

#endif /* flyingObject_h */ 

Last edited on
Undefined symbols for architecture x86_64:
"Velocity::Velocity()", referenced from


This indicates that the constructor for a Velocity object cannot be found. Where is it? Your linker can't find it. If that function is in Velocity.cpp , then are you building that file into Velocity.o and are you feeding it to the linker?
Topic archived. No new replies allowed.