15

I am getting a really weird error related to missing vtable for a given class constructor and destructor. Please help me to resolve this.

Undefined symbols for architecture i386:

  "vtable for A", referenced from:
      A::A() in A.o
      A::~MissionController() in A.o
  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Code snippet;

.h file:

class A: public B

  public:
     A();
    ~A();

};

.cpp file..

 A::A()   
{


}

A::~A()
{


}
user1908860
  • 509
  • 1
  • 9
  • 19
  • at the end of class put a `;` –  Mar 07 '13 at 07:09
  • 5
    NOTE: a missing vtable usually means the first non-inline virtual member function has no definition. – Bingo Mar 07 '13 at 07:10
  • i have done that..it was just a code snippet so typo. – user1908860 Mar 07 '13 at 07:11
  • 8
    I think your error is in the code that you have not posted. For example which _virtual_ functions are defined in CCNode – RvdK Mar 07 '13 at 07:12
  • i see this error, but where how to fix this. I have used similar type of code in several other classes but never seen this kind of error. – user1908860 Mar 07 '13 at 07:12
  • its not because of CCNode, if i remove that even though i see hit the same error. – user1908860 Mar 07 '13 at 07:13
  • 3
    As the compiler says, there is probably a missing virtual function. I often forget to include the definition of a pure virtual destructor, which actually is required in the case of a pure virtual destructor. – Bingo Mar 07 '13 at 07:15
  • Please post all the functions of MissionController – RvdK Mar 07 '13 at 07:15
  • There is no pure virtual function in any class. – user1908860 Mar 07 '13 at 07:18
  • There are no virtual functions in any class? CCNode's destructor should probably be virtual. As said above, the error is probably in the code you haven't posted. – Salgar Mar 07 '13 at 07:46
  • 1
    @user1908860, it's not possible to get this error if you remove the `CCNode` base, because a class doesn't need a vtable if it has no virtual functions. So you're not showing the real code, or you're not (re)building your project correctly after changing the code, or you're lying. – Jonathan Wakely Mar 07 '13 at 09:39
  • 1
    I got a similar error when I tried to override a non virtual parent method. – Paul-Sebastian Manole Dec 20 '14 at 20:36

3 Answers3

11

Found it,,trying with the sample, here is an exmaple.

class Shape{

public:
virtual int areas();
virtual void display();

virtual ~Shape(){};
};

The compiler complained

Undefined symbols for architecture x86_64:
"typeinfo for Shape", referenced from:
  typeinfo for trian in main_file.o
 "vtable for Shape", referenced from:
  Shape::Shape() in main_file.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)
  make: *** [cpp_tries] Error 1enter code here

The modification is empty or any inline content inside {} next to the virtual function

class Shape{

public:
    virtual int areas(){};
    virtual void display(){};

    virtual ~Shape(){};
};

Basically, its not finding the function definition for the non-inline virtual functions.

ravi.zombie
  • 1,482
  • 1
  • 20
  • 23
7

Ah! Mulling over this I think I get what is happening. I'm betting that CCNode is code which belongs to somebody else.

Any virtual functions you inherit are also virtual in the derived class... and it is common practice to make the destructor virtual... you might not realise the destructor is virtual.

Also if you are using somebody else's header file, but forgot to link to their object file, it might cause this error, as the linker would be missing the destructor of CCNode.

Bingo
  • 3,785
  • 6
  • 23
  • 27
1

Try to add virtual destructor to your class. CCNode propably contains some virtual methods and your compiler failed cope with it.

    class MissionController: public CCNode
    {

      public:
         MissionController();
        virtual ~MissionController();
    };

Is it some public framework, where can we see CCNode class definition? See vtable for .. referenced from compile error xcode or maybe http://www.parashift.com/c++-faq-lite/link-errs-missing-vtable.html for more help.

Community
  • 1
  • 1
Pihhan
  • 813
  • 5
  • 11