Page 1 of 1

C++ standard library support

Posted: Sat Nov 17, 2007 3:11 pm
by meh
Are there any tutorials on how to enable support for the C++ standard library in my kernel?

Posted: Sat Nov 17, 2007 3:39 pm
by label_3162073
e.. it seem to be impossible..

Posted: Sat Nov 17, 2007 4:02 pm
by JamesM
You'd have to write all your own template classes. The c++ standard library depends on a hosted environment.

Posted: Sat Nov 17, 2007 4:11 pm
by meh
Are there any other libraries that I can use with my operating system?

Posted: Sat Nov 17, 2007 4:50 pm
by JamesM
1. Your kernel is standalone - no libraries can be ported to it.
2. The programs that run on your OS (hosted by the kernel) can use libraries. Newlib is a good one to use (also libstdc++ can be used).

Notice they can only be used outside the kernel. That's what makes OS programming so interesting.

Re: C++ standard library support

Posted: Sat Nov 17, 2007 6:02 pm
by pcmattman
You'd have to have a complete port of the C library first (and I mean complete) first. Not to mention the fact that the C++ STL is apparently a nightmare to port.

Posted: Sat Nov 17, 2007 7:26 pm
by AndrewAPrice
AusZero wrote:Are there any other libraries that I can use with my operating system?
Try STLport, or Boost C++ Libraries. Although Boost technically isn't a C++ STL implementation, it's considered an extension of it and (I think) it can be used without an STL library.

EDIT: I didn't see "in my kernel". It's still possible. I've ported some things like malloc and strings to my kernel. Just replace the system calls with function calls!

Re: C++ standard library support

Posted: Mon Nov 19, 2007 1:35 am
by jnc100
AusZero wrote:Are there any tutorials on how to enable support for the C++ standard library in my kernel?
Well, if you follow the instructions at OS Specific Toolchain you'll end up with a libsupc++, libstdc++ and an include directory with all the stl stuff in. There are obviously a lot of dependencies on libgcc (which you also get for free) and libc (which you get, but it is tailored for userspace, so writing a smaller kernel version might make more sense). I have never tried stl in a kernel, but can't see why it shouldn't work (as long as you implement malloc, strcpy etc), but I can vouch for the functioning of libsupc++, including exceptions and rtti, all within kernel space within a few lines of startup (although you need a simple malloc, e.g a stack-based one, before your virtual memory manager starts).

Regards,
John.