Compiling C++ Kernel with objects

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
journey

Compiling C++ Kernel with objects

Post by journey »

Hi,

I've been reading some info on the osfaqs2 wiki, and have started with the bare bones C++ kernel available.

Managed to successfully build the kernel with the gcc cross-compiler using instructions from that wiki too, and have booted it with GRUB using Bochs.

Now I've created a simple class for writing to video, but I'm having a lot of problems compiling everything.

I figure would just compile each .cpp file separately for now (haven't gotten onto a Makefile), and then run ld, passing it all the final .o files.

My compilation commands are:
i586-elf-as -o loader.o loader.asm

i586-elf-gcc -o kernel.o -c kernel.cpp -Wall -Werror -nostdlib -nostartfiles -nodefaultlibs

i586-elf-gcc -o kernel_video.o -c kernel_video.cpp -Wall -Werror -nostdlib -nostartfiles -nodefaultlibs

However, "i586-elf-ld -T linker.ld -o kernel.bin kernel.o loader.o kernel_video.o" gives:

kernel.o(.text+0xf): In function `_main':
: undefined reference to `kvid'
.....
kernel.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'

Part of my kernel.cpp is as follows:

#include "kernel_video.h"

.....

void main(...) {
KernelVideo kvid;
kvid.WriteLine(".....");
...
}

I don't know where the __gxx_XXX stuff is coming from, since it was supposed to be just base gcc/g++ with no libraries or anything. And I'm not very experienced with all the subtleties of GCC, so very easy for me to go astray ;-)

Thanks for any help you people can provide me with =)
Adek336

Re:Compiling C++ Kernel with objects

Post by Adek336 »

--no-rtti --no-exceptions for more fun. ;)

__gxx_personality_v0 is exception-handling related.. so as long as you don't use the try {} catch {} blocks, it won't be ever executed. So, to satisfy the linker, create the function.

Code: Select all

[1] extern "C" void __gxx_personality_v0();
[2] void __gxx_personality_v0()
[3]  {
[4]   panic("what???? gxx_personality called???");
[5]  }
Line 1 tells the compiler not to mangle the function's name. Line 4 is for debugging. If for some obscure reason it IS called, you'll be the first to know. (as long as you implement a panic() call)

BTW, C++ kernel programming rules 8) Especially when using c++ over c only for namespaces/classes:) lol

Cheers,
Adrian
Post Reply