tags:

views:

114

answers:

2
A: 

The first problem usually appears when the class BaseClass is not polymorphic. Make sure it has at least one virtual function (a virtual destructor will do fine).

For the problem with AClass, make sure there has a .cpp file where the virtual methods of Aclass are defined. Make sure they aren't defined in the header file. Sadly there won't be any magical tool for this, at least to my knowledge.

Alexandre C.
+1  A: 

I believe both of these errors mean that the class has virtual functions, but no non-inline virtual functions (easy to do if you come from say a Java background). GCC emits the vtable and (I believe) typeinfo when it emits the first non-inline virtual function in a class. If all your virtual functions are inlined those bits won't be generated.

You'll need to move an inline virtual function to the source file and make it non-inline. The destructor is often a good candidate.

EDIT: I think I misread your question. What about temporarily making your virtual functions non-virtual so that the linker emits missing symbol for that exact function rather than for the vtable? You'd obviously have to remember to revirtualize them later.

EDIT2: When I tried to compile this I got a descriptive error. Can you paste in a minimal example that doesn't?

class Foo
{
public:
    virtual ~Foo();
};

int main()
{
    Foo foo;

    return 0;
}

Output:

Undefined                       first referenced
 symbol                             in file
Foo::~Foo()                         /var/tmp//cc4C2j6B.o
vtable for Foo                      /var/tmp//cc4C2j6B.o
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status
Mark B