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

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
User avatar
mrjbom
Member
Member
Posts: 322
Joined: Sun Jul 21, 2019 7:34 am

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

Post 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.
User avatar
Octacone
Member
Member
Posts: 1138
Joined: Fri Aug 07, 2015 6:13 am

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

Post 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
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
GMorgan
Posts: 22
Joined: Sun Jul 14, 2019 4:27 pm

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

Post 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
Post Reply