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
Minimal c++ implementation
- BrightLight
- Member
- Posts: 901
- Joined: Sat Dec 27, 2014 9:11 am
- Location: Maadi, Cairo, Egypt
- Contact:
Re: Minimal c++ implementation
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.
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.
Re: Minimal c++ implementation
I know, I want to implement the specific OS code.
So I have something like
So when I try to compile it, it says:
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.
So I have something like
Code: Select all
void _kernel()
{
std::cout < "Hello world!\n";
}
So I know I have to implement __ostream_insert as a member function in my OS so cout can work.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)'
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.
- thepowersgang
- Member
- Posts: 734
- Joined: Tue Dec 25, 2007 6:03 am
- Libera.chat IRC: thePowersGang
- Location: Perth, Western Australia
- Contact:
Re: Minimal c++ implementation
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
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
Re: Minimal c++ implementation
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
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
I just found it at bits/ostream_insert.h.
I hope you guys now understand what I'm trying to do
I hope you guys now understand what I'm trying to do
- max
- Member
- Posts: 616
- Joined: Mon Mar 05, 2012 11:23 am
- Libera.chat IRC: maxdev
- Location: Germany
- Contact:
Re: Minimal c++ implementation
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.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
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.