Page 1 of 1
Minimal c++ implementation
Posted: Mon Jul 25, 2016 10:21 pm
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
Re: Minimal c++ implementation
Posted: Mon Jul 25, 2016 10:35 pm
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.
Re: Minimal c++ implementation
Posted: Mon Jul 25, 2016 10:53 pm
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.
Re: Minimal c++ implementation
Posted: Mon Jul 25, 2016 10:58 pm
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).
Re: Minimal c++ implementation
Posted: Mon Jul 25, 2016 11:02 pm
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
Re: Minimal c++ implementation
Posted: Mon Jul 25, 2016 11:11 pm
by felknight
I just found it at bits/ostream_insert.h.
I hope you guys now understand what I'm trying to do
Re: Minimal c++ implementation
Posted: Mon Jul 25, 2016 11:42 pm
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.