# mingw AND virtual functions problem

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

## 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 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 statusthe line numbers into mozart.h are inside an indirect base class ofWidthPropagator.  This indirect base class has no virtual functions.I use #pragma interface/implementation.  Perhaps I did it wrong, but Ican'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 beWidthPropagator::getProfile. To save space, g++ only emits the vtable in theobject file containing a 'key' function. If you don't define the keyfunction, 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 theundefined key function, and so get an error.`

##### 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.

1. 1
2. 2
3. 3
4. 4
frob
15
5. 5

• 16
• 12
• 20
• 12
• 18
• ### Forum Statistics

• Total Topics
632161
• Total Posts
3004505

×