public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* GCC 10.2: undefined reference to vtable: missing its key function
@ 2021-06-06 21:41 Paul Smith
  2021-06-07 11:29 ` Paul Smith
  2021-06-07 14:19 ` Paul Koning
  0 siblings, 2 replies; 4+ messages in thread
From: Paul Smith @ 2021-06-06 21:41 UTC (permalink / raw)
  To: gcc

I have a class which is NOT, as far as I can see, polymorphic.

It doesn't inherit from any other class and none of its methods are
declared virtual.  The class implementation and all its callers all
compile just fine.

Is there some other way that a class can be thought to be virtual,
stealthily (say by its usage in some other class or something)?

The problem is that when I link this class I get a linker error from
gold:

  MyClass.h:25: error: undefined reference to 'vtable for MyClass'
ld: the vtable symbol may be undefined because the class is missing its
key function

Line 25 is the first method in the class (a constructor).

Sure enough if I use nm -C on the other object files I'm linking, I see
things like this:

   foo.o:  U vtable for MyClass

How can I figure out why the compiler decides, while compiling foo.cxx,
that MyClass is virtual and needs a vtable when as far as I can tell
it's not (if I use nm on MyClass.o I see no hints of vtable etc.)

This is with GCC 10.2 / binutils 2.35.1 (x86_64)


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-06-08 11:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-06 21:41 GCC 10.2: undefined reference to vtable: missing its key function Paul Smith
2021-06-07 11:29 ` Paul Smith
2021-06-07 14:19 ` Paul Koning
2021-06-08 11:45   ` Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).