Page 1 of 1

How do I use different C++ header files in my kernel code?

Posted: Tue Jul 30, 2019 10:01 am
by mrjbom
Hey.
In my kernel I wanted to use some header files from C++, for example vector. C++ compiles, but the ld linker throws an error.
Compile a kernel so:

Code: Select all

nasm -f elf32 ./source/kernel.asm -o kasm.o
g++ -m32 -std=c++11 -c ./source/kernel.cpp -o kc.o
ld -m elf_i386 -T link.ld -o kernel-0 kasm.o kc.o
Please help.

Re: How do I use different C++ header files in my kernel cod

Posted: Tue Jul 30, 2019 10:18 am
by Octacone
You can't, remember this is your OS, there are no standard libraries, nothing.
You have to write it yourself or port a third party one, I prefer the former.

Related:
https://wiki.osdev.org/C_Library
https://wiki.osdev.org/Creating_a_C_Library
https://wiki.osdev.org/C%2B%2B#Full_C.2 ... supc.2B.2B
https://wiki.osdev.org/How_kernel,_comp ... #C_Library

Re: How do I use different C++ header files in my kernel cod

Posted: Tue Jul 30, 2019 2:25 pm
by GMorgan
If you want to use something like vector in a kernel you need to:

1. Implement paging

2. Build an allocator against your paging

3. Tie that in as a custom allocator against vector or implement your own vector class