gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

C/C++ > undefined reference to `vtable for cSglBackground' - Help!

#8632 - Sweex - Wed Jul 16, 2003 11:49 pm

Help would be MUCH appreciated with the following, as I'm going mad!:-(

I'm using DevkitAdvance/gcc to compile my c++ code. Compiling with g++, having my code in several libraries (using ar).

All fine except for one thing; I get this error: undefined reference to `vtable for cSglBackground'. For some reason, g++ does not include a vtable for cSglBackground (has virtual functions obviously).

I have absolutely no idea why this is happening. Tried all kinds of combinations with -lm -lstdc++ -lsupc++ -lgcc -lc as linker parameters, it didn't seem to matter. cSglBackground doesn't have a destructor, but that should not matter (I've tried adding a (virtual) destructor), but it did not make a difference).

I am pretty clueless at this point!:-(

Thanks in advance,

.Sweex.

#8635 - Lord Graga - Thu Jul 17, 2003 12:07 am

to destroy something it must be there first.

#8636 - Sweex - Thu Jul 17, 2003 12:16 am

Erhm, in all respect; what's that supposed to mean?

#8654 - Sweex - Thu Jul 17, 2003 12:45 pm

Forgive my impatience, but does nobody have any clue?

#11592 - maximAL - Mon Oct 13, 2003 2:54 am

hmm, have you really defined the virtual function? just "virtual void bla(void);" won't work, you also have to define it, even if it is just empty, like "virtual void bla(void) {}"



hmm, i'm wondering if the thread starter is still into GBA dev *G*
maybe someone else has the same problem...

#11620 - ltaloc - Tue Oct 14, 2003 6:19 pm

Hello,
I have exactly the same problem when I define a PURE virtual function.
virtual void myFunction() = 0;
If this function is not a pure virtual - not "=0" - then it works fine.
So what I guess is that DevKit does not know pure virtual function. Thus you always have to implement your function, even if it is with an empty implementation - such as {}.
Cheers.

#11623 - tepples - Tue Oct 14, 2003 8:10 pm

ltaloc wrote:
So what I guess is that DevKit does not know pure virtual function.

DevKit Advance should have no problems with pure virtual methods. You just have to provide an implementation of write(). Details
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#11803 - ltaloc - Sun Oct 19, 2003 5:50 pm

Thank you tepples !

For C++ users, if you want to define write in a .cpp file, you need to put extern "C" int write(...) {
return 0;
}

#11829 - beelzebub - Mon Oct 20, 2003 11:51 pm

The vtable is only created by the compiler when you define the destructor, so make sure your class:

a) has a destructor (virtual of course)
b) you define the destructor some where (even if it's empty)
c) the file in with you define the destructor is included when you link.

#12342 - MumblyJoe - Sat Nov 08, 2003 2:05 pm

Yeah, you will have some problems with pure virtual (or abstract, whatever you call them) functions. The problem is that DevKitAdv doesn't provide an implementation of write() which gcc seems to use in a function that is called when a vtable cant be created. The only real way around this is:

a) write your own write() function.
b) dont use pure virtual functions.
c) use a nasty work around for virtual functions, such as declaring your functions and not defining them. I'm not sure how much gcc will like that approach though.
_________________
www.hungrydeveloper.com
Version 2.0 now up - guaranteed at least 100% more pleasing!