Minimal c++ implementation

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
felknight
Posts: 4
Joined: Mon Jul 25, 2016 10:07 pm
Libera.chat IRC: felknight

Minimal c++ implementation

Post by felknight »

I'm trying to make an OS full with c++

I want to use std::cout, which for start, uses this function:

std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, int)

With mangled name

_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_i

Which appears correctly in libstdc++11.a

But I don't know in which part of the gcc libstdc++ implementation (https://github.com/gcc-mirror/gcc) is

I searched everywhere, but it doesn't seem to be there, nore in glibc (haven't looked really in depth)

I want to find the original implementation so I can base mine on that

Hope you can help me! Thanks =D>
User avatar
BrightLight
Member
Member
Posts: 901
Joined: Sat Dec 27, 2014 9:11 am
Location: Maadi, Cairo, Egypt
Contact:

Re: Minimal c++ implementation

Post by BrightLight »

I can't really understand your question.
But to clarify something: you cannot use all the features of C++ or the C++ library or the runtime in your kernel; the C++ library and runtime contain OS-specific code.
You know your OS is advanced when you stop using the Intel programming guide as a reference.
felknight
Posts: 4
Joined: Mon Jul 25, 2016 10:07 pm
Libera.chat IRC: felknight

Re: Minimal c++ implementation

Post by felknight »

I know, I want to implement the specific OS code.

So I have something like

Code: Select all

void _kernel()
{
     std::cout < "Hello world!\n";
}
So when I try to compile it, it says:
undefined reference to 'std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, int)'
So I know I have to implement __ostream_insert as a member function in my OS so cout can work.

But I don't know what it does. So I'm trying to figure out where it is originally implemented. I looked up in gcc source where libstdc++ is. But I can't find __ostream_insert or anything similar related to ostream.
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Re: Minimal c++ implementation

Post by thepowersgang »

OS Development requires knowing how library features in your language work. In this case, it requires understanding how iostreams are actually implemented, and likely implementing them yourself (to back onto your kernel's logging framework, instead of using stdio like the userland library does).
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
felknight
Posts: 4
Joined: Mon Jul 25, 2016 10:07 pm
Libera.chat IRC: felknight

Re: Minimal c++ implementation

Post by felknight »

So what you're saying is that I shouldn't use libstdc++ headers and implement all the STL from scratch.

That seem a tremendous amount of work, the good thing about the STL is that is mostly headers.

I just want to implement the methods that are not declared in the headers like __ostream_insert
felknight
Posts: 4
Joined: Mon Jul 25, 2016 10:07 pm
Libera.chat IRC: felknight

Re: Minimal c++ implementation

Post by felknight »

I just found it at bits/ostream_insert.h.

I hope you guys now understand what I'm trying to do
User avatar
max
Member
Member
Posts: 616
Joined: Mon Mar 05, 2012 11:23 am
Libera.chat IRC: maxdev
Location: Germany
Contact:

Re: Minimal c++ implementation

Post by max »

felknight wrote:So what you're saying is that I shouldn't use libstdc++ headers and implement all the STL from scratch.

That seem a tremendous amount of work, the good thing about the STL is that is mostly headers.

I just want to implement the methods that are not declared in the headers like __ostream_insert
The problem is that libstdc++ is not meant to be used in kernel land, and to make it work, you will need to implement a lot of functions that it bases on (a big bunch of C functions) - which you usually don't really want in your kernel.

If you want to have something that behaves similar, so that you are able to code in the style you said, then just implement a minimal set yourself that looks and acts the same.

In the end it makes no sense to have libstdc++ in your kernel because you will usually not need it. When you have userspace applications, its a different story. You will then need a libc anyway, and then porting libstdc++ is way easier.
Post Reply