I am attempting to write a C++ kernel using GCC, but when i try and create classes with pure-virtual functions i get the following linker error:
"undefined reference to `___cxa_pure_virtual'"
What does this function actually do, and whats its prototype?
Cheers, Shmooze.
Pure Virtual Functions
RE:Pure Virtual Functions
I believe it's supposed to spit out some sort of error if you somehow manage to call it. In my "support.c" source that I link with C++ programs that don't have library support, I just have this:
void __pure_virtual(void)
{
}
And that appears to satisfy the linker. You may need to change the name to ___cxa_pure_virtual, depending on the version of GCC you're using at the moment.
void __pure_virtual(void)
{
}
And that appears to satisfy the linker. You may need to change the name to ___cxa_pure_virtual, depending on the version of GCC you're using at the moment.
RE:Pure Virtual Functions
Thanks! Its strange though, I thought that the only C++ language elements needing extra support functions were new/delete, exceptions, and constructor/destructors at startup/shutdown... clearly I was wrong
RE:Pure Virtual Functions
BTW, the definition I used (for DJGPP) was:
extern "C" void __cxa_pure_virtual(void)
{
}
as I couldn't work out the correct name without forcing the compiler not to mangle the name.
extern "C" void __cxa_pure_virtual(void)
{
}
as I couldn't work out the correct name without forcing the compiler not to mangle the name.
RE:Pure Virtual Functions
I'm pretty sure virtual functions require runtime support, since their purpose is runtime polymorphism.
RE:Pure Virtual Functions
runtime support is not really needed, the compiler will emit the vtables and generate the proper code to do the lookups. that function is what gets called if you somehow call a pure virtual function, which should never happen under normal circumstances.
my definitions is:
extern "C" void __cxa_pure_virtual() {
// FATAL ERROR! we just called a pure virtual function somehow...
panic("pure virtual function called in kernel!\n");
}
my definitions is:
extern "C" void __cxa_pure_virtual() {
// FATAL ERROR! we just called a pure virtual function somehow...
panic("pure virtual function called in kernel!\n");
}
RE:Pure Virtual Functions
If you manage to call it, you have a problem in your build process ..