Can i use C or C++ libraries ?

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
SmartBoy

Can i use C or C++ libraries ?

Post by SmartBoy »

Hello ..

i have question , can i use C or C++ libraries when i programming my OS , for example i wan't to use iostream.h library and write this code in kernel

Code: Select all

#include <iostream.h>

void main() {
cout << "Hello World !";
}
can i do it ?!.. 8)
Tora OS

Re:Can i use C or C++ libraries ?

Post by Tora OS »

nope. You got to rewrite it all.

so you will first have to write some text drivers like printf("string");
SmartBoy

Re:Can i use C or C++ libraries ?

Post by SmartBoy »

Tora OS wrote: nope. You got to rewrite it all.

so you will first have to write some text drivers like printf("string");
ok , written it by any language ? can i write it by C , and any open source example please .
AR

Re:Can i use C or C++ libraries ?

Post by AR »

You cannot use library functions, anything that requires you to "#include" any headers [which you did not write yourself] is not possible, everything [including the C/C++ standard library] must be written yourself (If your kernel is going to be Open Source then you can rip parts out of glibc).

See the wiki entry for the minimal conditions that the language you want to use must support. The main languages that are known to work well are C, C++, Pascal and Assembly.
SmartBoy

Re:Can i use C or C++ libraries ?

Post by SmartBoy »

AR wrote: You cannot use library functions, anything that requires you to "#include" any headers [which you did not write yourself] is not possible, everything [including the C/C++ standard library] must be written yourself (If your kernel is going to be Open Source then you can rip parts out of glibc).

See the wiki entry for the minimal conditions that the language you want to use must support. The main languages that are known to work well are C, C++, Pascal and Assembly.
ok , can i find any articles about this subject (write own libraries) and open source examples
AR

Re:Can i use C or C++ libraries ?

Post by AR »

There isn't really any specific source of information that I know of, you're expected to know what the functions do, combine that with knowledge of how the hardware works to recreate that functionality in the kernel. Also be aware that some functionality is simply too complex to support without an indepth understanding (ie. exceptions - stack unwinding).

For examples there is GRUB, Linux and BSD (All of which are C, not C++ though).
Tora OS

Re:Can i use C or C++ libraries ?

Post by Tora OS »

This might help you out some:

http://my.execpc.com/CE/AC/geezer/osd/libc/index.htm

AR wrote: There isn't really any specific source of information that I know of, you're expected to know what the functions do, combine that with knowledge of how the hardware works to recreate that functionality in the kernel. Also be aware that some functionality is simply too complex to support without an indepth understanding (ie. exceptions - stack unwinding).
Or you could just randomly write functions and comply to no standard functions and then have to rewrite all applications you port because you renamed half of the functions. ;)

I wouldnt recommend that, for reasons that should be all too clear.
raywill

Re:Can i use C or C++ libraries ?

Post by raywill »

Maybe you can refer to the Minix source code.

From that source code you will know which part of the OS you should write by your own(Actually,All) :)
Schol-R-LEA

Re:Can i use C or C++ libraries ?

Post by Schol-R-LEA »

SmartBoy wrote:
Tora OS wrote: nope. You got to rewrite it all.

so you will first have to write some text drivers like printf("string");
ok , written it by any language ? can i write it by C , and any open source example please .
The majority of it can be written in C (or any other suitable systems language), but at least some parts must be written in assembly, and you may want to write some other in assembly for efficiency.
mystran

Re:Can i use C or C++ libraries ?

Post by mystran »

Write everything you can in C. Then forget about efficiency, until someone complains about it, and then blame their code.

Seriously, very few library functions can benefit from assembler optimizations. Maybe memcpy/memmove/memset, but that's about it, and if I am not mistaken, compilers like GCC can generate fast inline code for those functions anyway, if you allow that.
Post Reply