LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-12-2017, 10:51 PM   #1
aimal
LQ Newbie
 
Registered: May 2017
Posts: 7

Rep: Reputation: Disabled
Post Needs of a C Library-- Building GCC


Hi,

I have a very basic question may be dummiest... from this https://github.com/kowalski100/gcc-t...ster/script.sh

Following are the steps to build GCC..
1. Build binutils
2. Build gcc
3. Build C-library
4. Again Build GCC

My qestions:
1. Why we build gcc twice, before and after c-library?
2. Why exactly we need C-Library especially if we are building toolchain for non-OS like arm-none-eabi??

Kind regards,
 
Old 10-13-2017, 01:53 AM   #2
hazel
LQ Guru
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 7,565
Blog Entries: 19

Rep: Reputation: 4446Reputation: 4446Reputation: 4446Reputation: 4446Reputation: 4446Reputation: 4446Reputation: 4446Reputation: 4446Reputation: 4446Reputation: 4446Reputation: 4446
This looks somewhat similar to the way LFS builds its toolchain. You start by building a statically linked gcc and binutils. The --with-newlib option tells the compiler not to use your host's libc. You use the new tools to build libc, then rebuild gcc to link to it. In LFS, you do that with binutils too.

You might like to compare with the Cross-LFS book at http://trac.clfs.org/wiki/read#CLFS3.0.0. I couldn't find a version of this book for ARM, but any of the versions will give you a general idea of how CLFS does it and why.

You need a C library on any system, whatever kind of processor you are using. It's the one library that every program needs to use.
 
Old 10-13-2017, 03:43 AM   #3
aimal
LQ Newbie
 
Registered: May 2017
Posts: 7

Original Poster
Rep: Reputation: Disabled
@Hazel, thank you so much for your kind reply. Let me explain what i understood from your answer.
We build GCC without any library, than using this newly build compiler to build c library. Then we build gcc again to link recently build c library to gcc.
BUT again:
Can you please explain a little bit how every C program uses C library?? What it offers to every program??
As far as i know only runtime library is required for every program which provide starup code for program... while the library we link is standard library. So how every program needs it?

Last edited by aimal; 10-13-2017 at 03:58 AM.
 
Old 10-13-2017, 05:40 AM   #4
hazel
LQ Guru
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 7,565
Blog Entries: 19

Rep: Reputation: 4446Reputation: 4446Reputation: 4446Reputation: 4446Reputation: 4446Reputation: 4446Reputation: 4446Reputation: 4446Reputation: 4446Reputation: 4446Reputation: 4446
It would be very hard to write a program that didn't use the standard C library! libc provides:
1) All the functions for input and output (screen, keyboard or files)
2) All the arithmetic functions
3) Functions for opening and closing files and using directories
4) Functions for handling time differences
5) Functions for handling character sets in different languages
6) Functions for communicating with the kernel (system calls) and with other processes

...and lots more!

You can get a better idea by reading the GNU libc manual at https://www.gnu.org/software/libc/ma...mono/libc.html.
 
1 members found this post helpful.
Old 10-13-2017, 07:18 AM   #5
aimal
LQ Newbie
 
Registered: May 2017
Posts: 7

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by hazel View Post
It would be very hard to write a program that didn't use the standard C library! libc provides:
1) All the functions for input and output (screen, keyboard or files)
2) All the arithmetic functions
3) Functions for opening and closing files and using directories
4) Functions for handling time differences
5) Functions for handling character sets in different languages
6) Functions for communicating with the kernel (system calls) and with other processes

...and lots more!

You can get a better idea by reading the GNU libc manual at https://www.gnu.org/software/libc/ma...mono/libc.html.
Thanks Hazel. It means the data types are also defined by C library?? And arent there special instructions for arithematic operation like ADD, MUL, SUB. Which are independent of C library.
 
Old 10-13-2017, 11:11 AM   #6
hazel
LQ Guru
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 7,565
Blog Entries: 19

Rep: Reputation: 4446Reputation: 4446Reputation: 4446Reputation: 4446Reputation: 4446Reputation: 4446Reputation: 4446Reputation: 4446Reputation: 4446Reputation: 4446Reputation: 4446
Quote:
Originally Posted by aimal View Post
Thanks Hazel. It means the data types are also defined by C library?? And arent there special instructions for arithematic operation like ADD, MUL, SUB. Which are independent of C library.
Basic data types like int, float and char are defined by the C language. The language also provides standard arithmetical operators like +, -, * and /. But all mathematical functions (trigonometry, logs, square roots and so on) come from the math library which is part of libc.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Building LFS with another C library? moisespedro Linux From Scratch 3 11-15-2014 09:21 AM
[SOLVED] chapter 5.5 building gcc cannot find gcc directory sfzombie13 Linux From Scratch 14 04-16-2014 07:31 PM
[SOLVED] Gcc error building tools on 7.4.rc1 chapter 5.10. GCC-4.8.1 - Pass 2 Keith Hedger Linux From Scratch 3 08-29-2013 11:30 AM
building library with automake joloboff Programming 1 04-17-2012 04:01 AM
Guidelines for building a C++ Class library. liguorir Programming 2 12-05-2003 09:40 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:09 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration