Page 1 of 1

undefined reference to `vtable for __cxxabiv1::__class_type_

Posted: Wed Apr 12, 2017 7:41 pm
by bodgergely
Hello Guys,

I am writing a kernel for like 2 months now and converted the project to C++ but virtual function do not seem to work for me.
I have CPPFLAGS?=-O2 -g -fno-exceptions -fno-rtti and also defined in a .cpp file the extern "C" void __cxa_pure_virtual().
Still getting this:
i686-elf-g++ --sysroot=/home/geri/workspace/bodos/src/../sysroot -isystem=/usr/include -T arch/i386/linker.ld -o bodos.kernel -D__is_kernel -Iinclude -ffreestanding -Wall -Wextra arch/i386/crti.o arch/i386/crtbegin.o arch/i386/boot.o arch/i386/tty.o arch/i386/cursor.o arch/i386/io.o arch/i386/serialport.o arch/i386/gdt.o arch/i386/init.o arch/i386/gdt_load.o arch/i386/isr.o arch/i386/isr_irq.o arch/i386/idt.o arch/i386/interrupt_x86.o arch/i386/irq.o arch/i386/timer.o arch/i386/keyboard.o arch/i386/paging.o arch/i386/sched/ctxswitch.o arch/i386/sched/switch.o kernel/kernel.o kernel/kprintf.o kernel/debug.o kernel/mem/allocator.o kernel/mem/kmalloc.o kernel/utils/random.o kernel/tests/RandomTest.o kernel/tests/TestCenter.o -nostdlib -lk -lgcc arch/i386/crtend.o arch/i386/crtn.o
arch/i386/sched/ctxswitch.o:(.rodata._ZTIN9scheduler3PooE[typeinfo for scheduler::Poo]+0x0): undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
arch/i386/sched/ctxswitch.o:(.rodata._ZTIN9scheduler3FooE[typeinfo for scheduler::Foo]+0x0): undefined reference to `vtable for __cxxabiv1::__class_type_info'
collect2: error: ld returned 1 exit status
Makefile:61: recipe for target 'bodos.kernel' failed

Does anyone know how to resolve this or I might be doing wrong?

Thanks a lot!

Greg

Re: undefined reference to `vtable for __cxxabiv1::__class_t

Posted: Wed Apr 12, 2017 8:02 pm
by Geri
what this point is i writing is possibly totally bullshit. do not pay attention to it:

virtual functions are not real functions, they are function pointers, and they must be managed by the cpp runtime - maybe even relying on a memory manager - which you probably cant have by the system if you are making your own os.
oop on low level is not a good idea, its too ,,high''

you must disable all shared library, runtime library, etc and maybe the compiler will fallback to methonds capable to work ( --disable-shared , etc) or not

Re: undefined reference to `vtable for __cxxabiv1::__class_t

Posted: Wed Apr 12, 2017 8:17 pm
by bodgergely
As per http://wiki.osdev.org/C%2B%2B
"A lot of features C++ offers can be used on-the-fly; they require no additional support or code to use them properly (e.g. templates, classes, inheritance, virtual functions). There are however other parts of C++ that do require runtime support, which will be discussed in this article."

"RTTI is used for typeid and dynamic_cast. It requires runtime support as well. Disable it with -fno-rtti. A kernel has no access to run-time features, which are most likely operating system-dependent. Note that virtual functions work without RTTI."

Re: undefined reference to `vtable for __cxxabiv1::__class_t

Posted: Wed Apr 12, 2017 9:00 pm
by bodgergely
Sorry guys it was a mistake I made.
Long story short I was not really adding the -fno-exceptions -fno-rtti to the file I had to compile with virtual support.
I should have taken a closer look.
It works now.

Re: undefined reference to `vtable for __cxxabiv1::__class_t

Posted: Thu Apr 13, 2017 1:28 am
by dozniak
Geri wrote:what this point is i writing is possibly totally bullshit. do not pay attention to it:

virtual functions are not real functions, they are function pointers, and they must be managed by the cpp runtime - maybe even relying on a memory manager - which you probably cant have by the system if you are making your own os.
oop on low level is not a good idea, its too ,,high''

you must disable all shared library, runtime library, etc and maybe the compiler will fallback to methonds capable to work ( --disable-shared , etc) or not
It IS bullshit, why did you write that?