Libc
Libc
Why do i have to make a Libc? I fail to see why it is the kernels problem to create a library for C programs. Would the compiler that makes the programs link it's own Libc into the program? And don't most operating systems use a Win32API style API made of DLL's instead now?
Re: Libc
Well, suppose you call fopen. That probably calls some low-level open call, which calls the kernel to open the file. Not every kernel opens files in the same way...Tyler wrote:Why do i have to make a Libc? I fail to see why it is the kernels problem to create a library for C programs.
msvcrt is the C library on Windows, and it comes with windows. The compiler doesn't care what C library you use, so long as it hass all of the necessary functions.Tyler wrote:Would the compiler that makes the programs link it's own Libc into the program?
The Win32 API is (as I understand it) the set of low-level calls. Every operating system has them at some level, and they are used. But, the standard C library is, well, standard. It provides things like printf, which had better make some kernel calls... and most programs would use it. On the other hand, there are some masochistic programmers who, on UNIX, convert, say, ints to strings by hand, and then use write to output it. (I haven't programmed on Windows significantly, so I dont know what the equivalent calls are. Probably WriteFile or something...).Tyler wrote:And don't most operating systems use a Win32API style API made of DLL's instead now?
Further, the Windows design is only one design. Many people feel that the UNIX design is cleaner (including me), others love the design of BeOS.
But, if you want other developers, you need to include a C library.
And why exactly would my kernel call fopen... just so that it can use some library which then calls kernel functions i could have called in the first place?
Also the Win32API is a set of high level DLL's which provides huge amounts of code which in turn call the low level functions as needed.
If all other programs on windows use the msvcrt... why does GCC (DJGPP) not call it? Also i am not interested in jsut hwo windows do it... i want to know how they all do it... but this more theoretical
Also the Win32API is a set of high level DLL's which provides huge amounts of code which in turn call the low level functions as needed.
If all other programs on windows use the msvcrt... why does GCC (DJGPP) not call it? Also i am not interested in jsut hwo windows do it... i want to know how they all do it... but this more theoretical
- Brynet-Inc
- Member
- Posts: 2426
- Joined: Tue Oct 17, 2006 9:29 pm
- Libera.chat IRC: brynet
- Location: Canada
- Contact:
1) If you write a kernel (only), you don't need a Libc. (How did you get the impression that it would?)
2) If you want to have a Libc on your system, that requires calling the kernel in some places, like, opening / reading from / writing to a stream, allocating memory, reading current system time, that kind of stuff. You will see where this is depending on the actual services that the kernel provides; unless your kernel mimics existing ones like POSIX, which would enable you to use existing Libc's out-of-the-box, you would either have to adapt an existing Libc, or write your own. (Or leave it up to a third party, see 1) above.)
3) The rest of your posting is unclear, because I cannot make out whether, by saying "Libc", you mean a standard library (printf(), malloc(), fopen()), or just some library (PrintSome(), AllocateMemory(), OpenFile()).
2) If you want to have a Libc on your system, that requires calling the kernel in some places, like, opening / reading from / writing to a stream, allocating memory, reading current system time, that kind of stuff. You will see where this is depending on the actual services that the kernel provides; unless your kernel mimics existing ones like POSIX, which would enable you to use existing Libc's out-of-the-box, you would either have to adapt an existing Libc, or write your own. (Or leave it up to a third party, see 1) above.)
3) The rest of your posting is unclear, because I cannot make out whether, by saying "Libc", you mean a standard library (printf(), malloc(), fopen()), or just some library (PrintSome(), AllocateMemory(), OpenFile()).
Every good solution is obvious once you've found it.
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Different OSes have different architectures. Windows has graphics contained in the kernel. On linux you commonly have to start a separate program before you can do graphics (the X server).Why do i have to make a Libc?
The C Library is a set of functions that work according to a defined standard. Specifically, its required for C. This means that on any compliant C compiler, you can compile and run code that relies only on libc, independent of platform.
However, to have each call to the c library have effect, the c library generally must call the operating system. This is the tricky part: A lot of libc is fixed, while oses vary considerably. The os developer has to write the functions needed for the C library as they are dependent on the kernel. Officially, you cant claim you can compile c programs for your os if you dont have a complete C library.
It isnt. In fact you probably missed somebody's point.I fail to see why it is the kernels problem to create a library for C programs.
the kernel does not provide a C library. The C library is a layer between the application and the kernel. If you dont use C for your applications, you don't need it.
Officially, a c compiler needs a libc to adhere to the c standard. Consequently they all have one. If you port a c compiler to your os, you'll have to give it a libc it can use.Would the compiler that makes the programs link it's own Libc into the program?
So, a compiler will use its own libc, but only after you have given it to the compiler
The Windows API is just the interface of one operating system. There a probably some oses that have adopted this style, and there are a lot that are completely different.And don't most operating systems use a Win32API style API made of DLL's instead now?
However, modern OSes do use a shared library for libc. In windows this is msvcrtxx.dll, under linux its generally libc.so
That doesnt mean shared libraries are easier than static libraries, they are just more efficient.
p.s. Solar beat me to commenting on some points, posting it anyway for completeness sake
- kataklinger
- Member
- Posts: 381
- Joined: Fri Nov 04, 2005 12:00 am
- Location: Serbia
It goes something like this:
user code <---> _LIBRARY_ <-using sys. calls-> kernel
If the _LIBRARY_ includes standard C library, there will be some applications you only have to recompile (I don't think it is a big number) and not to rewrite completely. At least what you get is that the others developers can easier move to your OS.
user code <---> _LIBRARY_ <-using sys. calls-> kernel
If the _LIBRARY_ includes standard C library, there will be some applications you only have to recompile (I don't think it is a big number) and not to rewrite completely. At least what you get is that the others developers can easier move to your OS.
I got the impression because every introduction i have read to OS Development says "you will need to implement your own c library". I think from all the theoretical answers here it is assumed that the OS writer will be it's only user, clearly i asked the question far to generally.Solar wrote:1) If you write a kernel (only), you don't need a Libc. (How did you get the impression that it would?)
2) If you want to have a Libc on your system, that requires calling the kernel in some places, like, opening / reading from / writing to a stream, allocating memory, reading current system time, that kind of stuff. You will see where this is depending on the actual services that the kernel provides; unless your kernel mimics existing ones like POSIX, which would enable you to use existing Libc's out-of-the-box, you would either have to adapt an existing Libc, or write your own. (Or leave it up to a third party, see 1) above.)
3) The rest of your posting is unclear, because I cannot make out whether, by saying "Libc", you mean a standard library (printf(), malloc(), fopen()), or just some library (PrintSome(), AllocateMemory(), OpenFile()).
I did not mean how does the kernel provide a library for Applications. I Have already developed a working barrier between the two. I simply wanted to know how libc specifically related to kernel development. Clearly they are unrelated and it would be a task for my systems compiler and any other compilers written for it.
Sorry if my question seemed backward i was put off the theory by the many operating system sources i download that contain a libc folder. It can all be highly confusing.
- kataklinger
- Member
- Posts: 381
- Joined: Fri Nov 04, 2005 12:00 am
- Location: Serbia
Yeah i already implemented that which is why i had so much confusion as to how to implemement the malloc in libc... in the end i just treated them as completely seperate routines that have no relation to each other... which seems the only logical position.kataklinger wrote:Well, you still need strcopy, strlen, memcpy, memset, (k)malloc, (k)free... even if you are in kernel, and that means you must implement no you own (or some code you can copy/paste)!
Well, no, the C lib is not "part" of the kernel.
However, it gives you a good impression of what will be required of the kernel, as a bare minimum of system services, to successfully host ANSI C userspace applications. Of course you can leave it to "compiler vendors" to implement it... but how many compiler vendors do you think your system will attract, if it does come without a Libc?
Ergo, you can write a "complete" kernel without a C library. But to have a complete operating system, at least in my book, you will have to provide at least one compiler / libc to go with it, or it will remain "kernel-only".
However, it gives you a good impression of what will be required of the kernel, as a bare minimum of system services, to successfully host ANSI C userspace applications. Of course you can leave it to "compiler vendors" to implement it... but how many compiler vendors do you think your system will attract, if it does come without a Libc?
Ergo, you can write a "complete" kernel without a C library. But to have a complete operating system, at least in my book, you will have to provide at least one compiler / libc to go with it, or it will remain "kernel-only".
Every good solution is obvious once you've found it.