OSDev.org
https://forum.osdev.org/

How do I use different C++ header files in my kernel code?
https://forum.osdev.org/viewtopic.php?f=1&t=33800
Page 1 of 1

Author:  mrjbom [ Tue Jul 30, 2019 10:01 am ]
Post subject:  How do I use different C++ header files in my kernel code?

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:
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.

Author:  Octacone [ Tue Jul 30, 2019 10:18 am ]
Post subject:  Re: How do I use different C++ header files in my kernel cod

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.2B.2B_Runtime_Support_Using_libgcc_And_libsupc.2B.2B
https://wiki.osdev.org/How_kernel,_compiler,_and_C_library_work_together#C_Library

Author:  GMorgan [ Tue Jul 30, 2019 2:25 pm ]
Post subject:  Re: How do I use different C++ header files in my kernel cod

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

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/