Sign in to follow this  

mingw AND virtual functions problem

This topic is 4834 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm using the last Dev-c++ beta with mingw. My code uses virtual functions but compiling it results in some of the following error:
In function xyz undefined reference to `vtable for Tuner'.
Searching a bit with google I discovered that this is a pretty common issue, but I was not able to find a solution. It seems (but I'm not sure of that), that this is a bug in some of the latest versions of gcc, is this true? What could I do? Thank you

Share this post


Link to post
Share on other sites
I'll copy and paste the results from the 2nd link after entering the following into google, including quotes:

"undefined reference to `vtable for"

undefined reference to `vtable for ...'

* From: Denys Duchier <Denys dot Duchier at ps dot uni-sb dot de>
* To: gcc-bugs at gcc dot gnu dot org
* Date: Thu, 05 Sep 2002 00:56:33 +0200
* Subject: undefined reference to `vtable for ...'

OK, I give up, what does this mean:

var_of.o: In function `WidthPropagator::WidthPropagator[not-in-charge](unsigned, unsigned)':
/home/denys/Mozart/mozart-gcc3/mozart/platform/emulator/mozart.h:725: undefined reference to `vtable for WidthPropagator'
var_of.o: In function `WidthPropagator::WidthPropagator[in-charge](unsigned, unsigned)':
/home/denys/Mozart/mozart-gcc3/mozart/platform/emulator/mozart.h:725: undefined reference to `vtable for WidthPropagator'
var_of.o: In function `WidthPropagator::getProfile() const':
/home/denys/Mozart/mozart-gcc3/mozart/platform/emulator/mozart.h:722: undefined reference to `WidthPropagator::profile'
var_of.o: In function `MonitorArityPropagator::MonitorArityPropagator[not-in-charge](unsigned, unsigned, unsigned, unsigned, unsigned)':
/home/denys/Mozart/mozart-gcc3/mozart/platform/emulator/mozart.h:725: undefined reference to `vtable for MonitorArityPropagator'
var_of.o: In function `MonitorArityPropagator::MonitorArityPropagator[in-charge](unsigned, unsigned, unsigned, unsigned, unsigned)':
/home/denys/Mozart/mozart-gcc3/mozart/platform/emulator/mozart.h:725: undefined reference to `vtable for MonitorArityPropagator'
var_of.o: In function `MonitorArityPropagator::getProfile() const':
/home/denys/Mozart/mozart-gcc3/mozart/platform/emulator/mozart.h:722: undefined reference to `MonitorArityPropagator::profile'
collect2: ld returned 1 exit status

the line numbers into mozart.h are inside an indirect base class of
WidthPropagator. This indirect base class has no virtual functions.
I use #pragma interface/implementation. Perhaps I did it wrong, but I
can't see it. Any suggestions?


Re: undefined reference to `vtable for ...'

* From: Nathan Sidwell <nathan at codesourcery dot com>
* To: Denys Duchier <Denys dot Duchier at ps dot uni-sb dot de>
* Cc: gcc-bugs at gcc dot gnu dot org
* Date: Thu, 05 Sep 2002 09:31:10 +0100
* Subject: Re: undefined reference to `vtable for ...'
* Organization: Codesourcery LLC
* References: <isadmxgy8u.fsf@elk.ps.uni-sb.de>

Denys Duchier wrote:

> /home/denys/Mozart/mozart-gcc3/mozart/platform/emulator/mozart.h:725: undefined reference to `vtable for WidthPropagator'

you have not defined all the functions declared in WidthPropagator. May be
WidthPropagator::getProfile. To save space, g++ only emits the vtable in the
object file containing a 'key' function. If you don't define the key
function, you won't get a vtable either. (there are some other cases).
This is not a bug, as even if you had the vtable, it'd reference the
undefined key function, and so get an error.

Share this post


Link to post
Share on other sites
Thank you for the help, but I already found this (as other dozen similar). I cannot understand what exactly does he mean with 'key-function': I have pure virtual void, virtual with implementation and common method in the same class. This is the first time I use virtual functions in a c++ project but as long as I know, I used them right.

Share this post


Link to post
Share on other sites

This topic is 4834 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this