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 ↗


💗 Help shape the future: Sponsor/Donate


Recommended Topics:
Featured Video:
Watch on Youtube - x20f Code with Kiran - Live Coding | Linux Kernel Programming | Kernel Libraries | Part 1 ↗

Multi-Client TCP Server with pthreads Mutex Synchronized - Code-walk of viewer code - Sekhar Pariga ↗
Saturday' 26-Sep-2020
Here is a code-walk of a git-hub source submitted by a viewer Sekhar Pariga, which is a Multi-client TCP Server with pthreads Mutex synchronized. Basically it is a Directory Listing Server, that serves ls, cd, pwd of directory functions to connecting TCP clients which are remotely (locally) executed by the server. Server is implemented using multi-thread pthread library, to serve multiple clients simultaneously. Server keeps the each accepted client session details in the queue data structure. Client session queue contains each clients socket-fd and present working directory as a queue node.

Adding your own Kernel Modules into Linux Kernel Source | Linux Kernel Programming ↗
Saturday' 26-Sep-2020
Whenever you do custom kernel modules, you can optionally make it a part of existing Linux Kernel source. This does not mean you are submitting your kernel module to the mainline kernel source (i.e kernel.org Linux Kernel Foundation). What I meant is, you can make your kernel module(s) part of Linux Kernel source so that when you compile your kernel you can automatically compile your kernel module(s) too. As well when you create/modify kernel .config configuration file (such as via make menuconfig, etc), you can enable or disable your kernel module(s) too.
To do the same you have to register (and include) your custom Kernel Module's Kconfig and Makefile to the existing Kconfig and Makefile of the Linux Kernel source Here is a detailed multi-episode video of mine which gives the overall idea and the big-picture.

Roadmap - How to become Linux Kernel Developer - Device Drivers Programmer and a Systems Software Expert ↗
Saturday' 26-Sep-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 03 - July 2020 ↗
Saturday' 26-Sep-2020
The Linux Channel :: Weekly News Digest - Week 03 - July 2020
> Linux founder tells Intel to stop inventing 'magic instructions' and 'start fixing real problems'
> QNAP launches its first 2.5GbE network switch - QSW-1105-5T
> Japan's ARM-based Fugaku is the world's fastest supercomputer
> FreeBSD Back To Seeing Progress On 802.11ac WiFi Support, Ath10k Driver
> Sparkfun Launches the ZED-F9R GPS Dead Reckoning Raspberry Pi pHAT for Mobile Robots
> ODROID-N2 Plus SBC Gets Amlogic S922X Rev. C Processor Clocked at up to 2.4 GHz
> Rock Pi E SBC Comes with WiFi, Bluetooth, Two Ethernet Ports, and Optional PoE

IP-in-IP Tunneling Demystified - VPN Tunnels ↗
Saturday' 26-Sep-2020
There can be many ways one can architect VPN Networks. The end objective is to tunnel private IP (typically LAN subnets) within public IP Networks (such as Internet). You can establish such a tunnel in various creative ways, such as Transport Mode, Tunnel Mode, IP-in-IP tunneling, etc. Also you can choose any transport layer protocol of your choice such as send VPN traffic via TCP, or via UDP and so on.

Nmap Network Scanning ↗
Saturday' 26-Sep-2020

Linux and Open-Source Communities across the world ↗
Saturday' 26-Sep-2020
Here is a small list of Linux (Kernel, Linux Users Group) and Open-Source Communities across the world.

Linux Kernel Network Programming - Transport Layer L4 TCP/UDP Registration - Protocol APIs ↗
Saturday' 26-Sep-2020

PHP installation ↗
Saturday' 26-Sep-2020

Management ↗
Saturday' 26-Sep-2020


Trending Video:
Watch on Youtube - x20f Code with Kiran - Live Coding | Linux Kernel Programming | Kernel Libraries | Part 1 ↗

Interactive map of Linux Kernel ↗
Saturday' 26-Sep-2020



Recommended Video:
Watch on Youtube - x20f Code with Kiran - Live Coding | Linux Kernel Programming | Kernel Libraries | Part 1 ↗