HOMECOURSESSTUDENTSDONATIONSVIDEOSEVENTSTUTORIALSLINKSNEWSCONTACT


TUTORIALS 》 Compiling a C Compiler with a C Compilter | Compile gcc with gcc

As we know the fundamental aspect of a programming language compiler is to translate code written from language to other. But most commonly compilers will compile(i.e translate) code written in high-level human friendly language such as C, C++, Java, etc. to native CPU architecture specific (machine understandable) binary code which is nothing but sequence of CPU instructions.

If we see that way we should able to perfectly compile a source-code of a C compiler with another C compiler run-time binaries. In that way we should able to perfectly compile an entire gcc compiler source-code with an installed gcc compiler. We can get the gcc compiler sources via github: https://github.com/gcc-mirror/gcc or in a Ubuntu system we can get the desired gcc source code for a specific version via:

$ apt source gcc-9

NOTE: since we are getting sources via apt-get(or apt) command, we do not have to provide sudo access.

However it is important to know that source code downloaded via github may require different run-time dependencies vs what is currently installed in your Linux system, vs when you get gcc source via Ubuntu apt command and choose a version which is close to your installed gcc compiler, then the run-time dependencies which are required for this source may match with whatever currently installed on your Ubuntu OS install.

Like any open-source project you can browse through any compilation/installation steps/documentation. Typially you should get in files such as README, or INSTALL, etc. But in the case of gcc, they provided few user-friendly web html documentation (as should below) which you can open in a browser and follow the steps and mainly various options and prerequisites.
gcc soruce code and Installation Guide
gcc HTML Installation Guide page 1
gcc HTML Installation Guide page 2
gcc HTML Installation Guide page 3
gcc HTML Installation Guide page 4
gcc HTML Installation Guide page 5

You can now proceed compilation and before that install dependencies(i.e third-party libraries) if any. Once everything is done, you can see the the custom compiled gcc binaries are installed in a custom directory path so as to not disturb the Ubuntu OS module installed gcc binaries.

[email protected]:/code/gcc/install$ ls
test  test.c  usr
[email protected]:/code/gcc/install$ ./usr/local/bin/gcc -v
Using built-in specs.
COLLECT_GCC=./usr/local/bin/gcc
COLLECT_LTO_WRAPPER=/code/gcc/install/usr/local/bin/../libexec/gcc/x86_64-pc-linux-gnu/9.2.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ./configure --disable-multilib
Thread model: posix
gcc version 9.2.0 (GCC) 

You can now do a test compilation of a sample C source-code file (test.c) with the current compiled gcc compiler (i.e ./usr/local/bin/gcc) as shown below:

[email protected]:/code/gcc/install$ ./usr/local/bin/gcc -o test test.c
[email protected]:/code/gcc/install$ ./test
hello world
[email protected]:/code/gcc/install$ cat test.c
#include 
void main()
{	
	printf("hello world\n");
}
[email protected]:/code/gcc/install$

Here is my two-part Youtube video episode series which shows you all the steps from start to finish in a live demo screen capture.
If you have any queries or anything to discuss, kindly send me a mail to: [email protected]

Also recommend to watch:


Featured Video:



Suggested Topics:


☆ Tutorials :: Arduino UNO Projects ↗


☆ Tutorials :: Network Software Development ↗


☆ Tutorials :: Research and Projects ↗


☆ Tutorials :: Linux (user-space), Systems Architecture ↗


☆ Tutorials :: Linux Kernel Software Development ↗


☆ Tutorials :: Linux Kernel Internals (PDFs) - by Ramin Farajpour ↗


☆ Tutorials :: Software Development (Programming) Tools ↗


☆ Tutorials :: Embedded Projects ↗

Join The Linux Channel :: Facebook Group ↗

Visit The Linux Channel :: on Youtube ↗


Join a course:

💎 Linux, Kernel, Networking and Device Drivers: PDF Brochure
💎 PhD or equivalent (or Post Doctoral) looking for assistance: Details
💎 ... or unlimited life-time mentorship: Details


💗 Help shape the future: Sponsor/Donate


Recommended Topics:
Featured Video:
Watch on Youtube - [132//0] Online Course - Linux CLI Scripting - Episode6 - $head command ↗

Roadmap - How to become Linux Kernel Developer - Device Drivers Programmer and a Systems Software Expert ↗
Wednesday' 15-Jul-2020
Many viewers and even sometimes my students ask me how I can become a kernel programmer or just device driver developer and so on. So I shot this video (and an add-on video) where I summarized steps and a roadmap to become a full-fledged Linux Kernel Developer.

Weekly News Digest - Week 02 - July 2020 ↗
Wednesday' 15-Jul-2020
The Linux Channel :: Weekly News Digest - Week 02 - July 2020
> Google is teaming up with Ubuntu to bring Flutter apps to Linux
> Linux kernel developers: This new BLM coding style avoids words like blacklist
> Zstd'ing The Kernel Might See Mainline With Linux 5.9 For Faster Boot Times
> Linux 5.9 To Bring Arm Memory Tagging Extension Support
> Linux Kernel Raising Compiler Build Requirement To GCC 4.9
> Linux Developers May Discuss Allowing Rust Code Within The Kernel
> Premio Unveils Intel 9th Gen Industrial Motherboard For Advanced Embedded And IoT Solutions

Linux Kernel Module to Drop Packets captured via netfilter hooks ↗
Wednesday' 15-Jul-2020
Here is my sample Kernel Module to drop packets (i.e sk_buff instance) captured via netfilter hooks. When you want to drop packets in your custom netfilter hooks make sure you never do a manual kfree_skb(skb) API call. Since it is anyway performed once the flow of the code moves out of your kernel module netfilter hook. All you need to do is to return NF_DROP to drop gracefully the desired packet. Here is my detailed video and a sample Linux Kernel module.

CEO, CTO Talk ↗
Wednesday' 15-Jul-2020

Arduino UNO - RO Water Purifier Controller ↗
Wednesday' 15-Jul-2020
Here is a Youtube VLOG of my DIY RO Water Purifier Controller done via Arduino UNO. I want the Arduino UNO to control the RO pump, so that it pumps for a specific duration and stops automatically. This is done via Opto-isolated 4 Channel 5V 10A Relay Board meant for Arduino UNO, Raspberry Pi or similar SoC boards which offers GPIO pins. To this relay I have connected the RO water purifier booster pump which works at 24V DC connected via 220V AC to 24V DC power supply adaptar. I have also connected a small active 5V buzzer to notify the progress and completion as it fills the tank/canister.

AT&T Archives: The UNIX Operating System ↗
Wednesday' 15-Jul-2020

Data-Plane and Control-Plane of a Networking Device ↗
Wednesday' 15-Jul-2020

Socket Options - Socket Programming - setsockopt(), getsockopt() ↗
Wednesday' 15-Jul-2020

PyDelhi + PyData + ILUG-D + Linux Chix meetup mash @ Sarai on 17-Dec-2016 ↗
Wednesday' 15-Jul-2020

Tour of my new Home Networking Lab within VirtualBox VM ↗
Wednesday' 15-Jul-2020


Trending Video:
Watch on Youtube - [131//0] 0x1ab Understanding Ecosystem - Windows vs Linux || The Linux Channel ↗

Bluefish IDE - a simple versatile light-weight best editor to edit kernel source files, html files, c source code, text files, SQL schema and so on ↗
Wednesday' 15-Jul-2020



Recommended Video:
Watch on Youtube - [137//0] 0x1fb a Riddle for viewers | You can participate ↗