wolfgang
wolfgang

Reputation: 7809

C++: what are the causes of " undefined reference to 'typeinfo for [class name]' "other than virtual functions

some of these errors are solved by modifying

    virtual void draw();

to

    virtual void draw() {};

BUT, what can be the other causes of these errors?, other than virtual functions.. What can be the cause of the following error..

  /tmp/cciGEgp5.o:(.rodata._ZTI14CustomXmppPump[typeinfo for CustomXmppPump]+0x18): 
  undefined reference to `typeinfo for XmppPump'

Upvotes: 11

Views: 18624

Answers (2)

Peter Tseng
Peter Tseng

Reputation: 14003

If you're compiling with RTTI (-frtti), make sure your dependent libraries are also compiled with it, and not -fno-rtti. Otherwise you will get the typeinfo error when you subclass a class compiled with -fno-rtti or use dynamic_cast.

Upvotes: 12

Dave S
Dave S

Reputation: 21123

In GCC, the first non-inline virtual method is used to determine the the translation unit where the vtable and typeinfo objects are created. If you then do not define that method, it creates the error you see, since it expected you define that method somewhere, and was waiting for that definition to emit the output of the vtable and typeinfo for the class.

http://gcc.gnu.org/onlinedocs/gcc/Vague-Linkage.html

When you change the declaration of virtual void draw(); to the inline definition of virtual void draw() {};, it picks a different function to emit the vtable.

Upvotes: 9

Related Questions