undefined virtual table: a misleading error message in egcs-2.91.66

Martin v. Loewis martin@loewis.home.cs.tu-berlin.de
Mon May 15 01:25:00 GMT 2000


> A program given below shows the problem. If defines a class foo with a pure
> virtual function fun. 

Thanks for your bug report. This is a known problem.

> Compiler sems to generate virtual table noly when a virtual function
> is implemented. Shouldn't virtual table be generated whenever it is
> referenced, e.g in constructor?

No. It is an optimization to only emit virtual tables, RTTI, and
out-of-line copies of inline virtual functions together with the first
non-pure non-inline virtual function. Using this optimzation gives
quite some savings in executable size.

It is also a legal optimization: The standard requires that *all*
virtual functions of a class must be defined, whether they are used or
not. In particular, the first such function must be defined, so the
compiler can trust that it will see a definition sometime.

> Can this be fixed?

Hardly. The error is detected by the linker, and the linker has no
knowledge what the first virtual function was. One possible scheme
could work like this:
- the compiler emits a hint to the linker telling it what the first
  virtual function was
- when the linker sees a missing virtual table symbol, it checks whether
  it also has a hint, and then prints an appropriate message

Unfortunately, this is very difficult to implement, especially on
systems where the linker is supplied by the OS vendor.

Regards,
Martin


More information about the Gcc-bugs mailing list