Page 1 of 1

Clarification of A cross compiler and C libaries?

Posted: Thu Mar 22, 2012 5:02 pm
by theelitenoob
Hi, i read the wiki article about cross compiling, and what its needed for. I have a working boot-loader, and am starting the kernel. However I am extremely confused. so here are my questions;
  1. Why exactly do you need a cross compiler? What purpose does it serve?
  2. So if you start up a kernel, what does it mean by porting the C libraries to your OS? And why do you need it?
  3. The kernel is used to do all the work for the OS, but how does it do the work without stdio.h or stdlib.h? How does the porting libraries work exactly, how does it help?

Re: Clarification of A cross compiler and C libaries?

Posted: Thu Mar 22, 2012 5:16 pm
by JamesM
Hi,
theelitenoob wrote:Hi, i read the wiki article about cross compiling, and what its needed for. I have a working boot-loader, and am starting the kernel. However I am extremely confused. so here are my questions;
  1. Why exactly do you need a cross compiler? What purpose does it serve?
  2. So if you start up a kernel, what does it mean by porting the C libraries to your OS? And why do you need it?
  3. The kernel is used to do all the work for the OS, but how does it do the work without stdio.h or stdlib.h? How does the porting libraries work exactly, how does it help?
A cross compiler helps by sanitising your environment and ensuring that you don't accidentally have code brought in by your compiler that you don't expect. Although, I'm not fully convinced of its immediate utility to a newcomer using Linux.

When you start writing a kernel, you have no C library available to help you. You will therefore need to write a subset of it - memcpy, memset, strcpy etc. . What subset you write is up to you, but you won't be able to write the whole lot - it's massive! Eventually you'll get to the point where you're starting user processes, and these will need a C library to link against. At that point, you port a full C library. You're nowhere near there yet.

Without stdio.h and stdlib.h - you'll have to write that functionality yourself. There are tutorials and articles on how to use serial ports and write to the screen - you have to write everything yourself.

Cheers,

James

Re: Clarification of A cross compiler and C libaries?

Posted: Thu Mar 22, 2012 5:42 pm
by theelitenoob
Oh, ok, so basically, i can start writing my kernel, but wherever I need a function, such as memcpy, or printf, i have to implement them myself, correct? So i don't need to link or port a library if I don't want to? Also, say I need printf, how would I make it print out to the screen? Just as an example.

Re: Clarification of A cross compiler and C libaries?

Posted: Thu Mar 22, 2012 5:45 pm
by Jezze
Yes you need to write them yourself.

To print to the screen you should read up on the wiki. It is dead easy.

Re: Clarification of A cross compiler and C libaries?

Posted: Thu Mar 22, 2012 6:21 pm
by theelitenoob
Ok, I'll look into it, thanks for the help mate. Also one last question, is it possible to completely write the OS, without porting any libraries?

Re: Clarification of A cross compiler and C libaries?

Posted: Thu Mar 22, 2012 6:23 pm
by VolTeK
Of course, you make your own libraries.

Re: Clarification of A cross compiler and C libaries?

Posted: Thu Mar 22, 2012 6:28 pm
by theelitenoob
Ok, good to know, time to get started!

Re: Clarification of A cross compiler and C libaries?

Posted: Fri Mar 23, 2012 5:02 am
by gravaera
Yo:
theelitenoob wrote:Hi, i read the wiki article about cross compiling, and what its needed for...
  1. Why exactly do you need a cross compiler? What purpose does it serve?
I thought that the wiki article was phrased excruciatingly verbosely and painstakingly optimised for even the least experienced of people. Just to clarify, did you read this specific article here...?

What about it did you not understand? Just for my own enlightenment, nothing else :)