Linker error: undefined reference to typeinfo for A with no-rtti option

Дмитрий Оксенчук oksenchuk89@gmail.com
Tue Apr 13 20:26:00 GMT 2010


$ g++ -c -o classes.o -fno-rtti classes.cpp
$ g++ -o test main.cpp classes.o
/tmp/ccmtJ65X.o:(.rodata._ZTI1B[typeinfo for B]+0x8): undefined
reference to `typeinfo for A'
collect2: ld returned 1 exit status

Code:
/* classes.h */
class A
{
public:
    virtual ~A();
};

class B: public A
{
};
/* end classes.h */

/* classes.cpp */
#include "classes.h"

A::~A()
{
}
/* end classes.cpp */

/* main.cpp */
#include "classes.h"

int main()
{
    B b_obj;
    return 0;
}
/* end main.cpp */

Linker doesn't say anything when i create any virtual function in B or
replace virtual ~A() to virtual void f() for example.

It seems like compiler doesn't create vtable for B class and try to
call ~B() using typeinfo for A, but what for?



More information about the Gcc-help mailing list