Clarification of A cross compiler and C libaries?

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
theelitenoob
Posts: 16
Joined: Wed Aug 24, 2011 11:19 am

Clarification of A cross compiler and C libaries?

Post 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?
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: Clarification of A cross compiler and C libaries?

Post 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
theelitenoob
Posts: 16
Joined: Wed Aug 24, 2011 11:19 am

Re: Clarification of A cross compiler and C libaries?

Post 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.
User avatar
Jezze
Member
Member
Posts: 395
Joined: Thu Jul 26, 2007 1:53 am
Libera.chat IRC: jfu
Contact:

Re: Clarification of A cross compiler and C libaries?

Post 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.
Fudge - Simplicity, clarity and speed.
http://github.com/Jezze/fudge/
theelitenoob
Posts: 16
Joined: Wed Aug 24, 2011 11:19 am

Re: Clarification of A cross compiler and C libaries?

Post 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?
User avatar
VolTeK
Member
Member
Posts: 815
Joined: Sat Nov 15, 2008 2:37 pm
Location: The Fire Nation

Re: Clarification of A cross compiler and C libaries?

Post by VolTeK »

Of course, you make your own libraries.
theelitenoob
Posts: 16
Joined: Wed Aug 24, 2011 11:19 am

Re: Clarification of A cross compiler and C libaries?

Post by theelitenoob »

Ok, good to know, time to get started!
User avatar
gravaera
Member
Member
Posts: 737
Joined: Tue Jun 02, 2009 4:35 pm
Location: Supporting the cause: Use \tabs to indent code. NOT \x20 spaces.

Re: Clarification of A cross compiler and C libaries?

Post 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 :)
17:56 < sortie> Paging is called paging because you need to draw it on pages in your notebook to succeed at it.
Post Reply