开发者

How to use STLPort in my kernel?

I am developing a kernel in C++. But I do not want to write a stdl开发者_JAVA百科ib; for that purpose I have downloaded STLport http://www.stlport.org/, but I don't know how to install and use it.

I am using Linux for building my kernel.

How can I use c++ standard libs in my kernel?

And I do not want to port all libs from STLport. How can I exclude a selection of libs? Like std::string, std::vector etc.


In order for STL to work you have to port several things like static initialization (for i.e. std::cin and std::cout) and stack unwinding...

you'd have to port i.e.: libsupc++ and have that in your kernel. Basically all this stuff shouldn't be in the Kernel in the first place. DON'T use Vectors use static arrays because vectors might reallocate your data!

also all that stuff will bloat your kernel for nothing!

you can have a look what L4 allows itself to be used in kernel. they don't do memory allocation and they don't do exceptions (unpredictable) and they especially don't do STL.

The latter links shall give you an idea what you need to port to get c++ operating system support. Libsupc++ is part of gcc. it's purpose is to encapsulate all the parts where runtime code is needed.

Useful information about libsupc++

Useful information about c++ operating system support


I would probably advise against using the STL in Kernel development. STL will assume some form of standard library support of which there is none in your kernel. Also most memory allocation operations have no bounds for the time that they can take and are therefore unsuitable for use in interrupt handlers. Exceptions are another thing that can cause major headaches in the kernel


I am not sure whether STL in kernel is actually good to have, but if you really want to try, it's very fun. I have written my own OS and when I had memory allocation in the kernel, the first thing I did was porting STLport (5.2.1). It was working well so far, although the kernel itself is still too preliminary.

Anyway, I can share some experience on porting it.

  1. Porting STLport requires no building and very few prerequisites, just include the headers and let the compiler know it's path (-I option for gcc). The template classes will be compiled with your cpp source files.

  2. STLport is configurable, you can disable what you can't afford and select what you want, such as iostream, debug, exception, RTTI and threading. Just checkout the documentation and then get to the configuration headers, it's very nicely commented (e.g. stlport/stl/config/user_config.h)

  3. As the most basic you'll need malloc and free, or maybe new, delete and variants. That's enough for porting std string, containers and algorithms, IIRC. But it's neither thread safe nor memory allocation optimized, you need to be very careful when you rely on it.

  4. You can do you own iostream, it's just template classes and global objects (BTW, I hacked ELF sections and manually initialized my global objects by calling the functions), but this needs more work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜