Table of Contents
This guide is about Guide: Run a C Compiler on Linux. So read this free guide, Guide: Run a C Compiler on Linux step by step. If you have query related to same article you may contact us.
Guide: Run a C Compiler on Linux – Guide
When building the Linux kernel, developers had to build a free open source compiler to create the kernel and modules. The GCC compiler was created in the GNU project. In the current version of all Linux distributions, the GCC compiler is pre-installed in the operating system. You can use the GCC compiler to compile C, C++, Ada, Go and some other object-oriented programming languages. You can compile code on your terminal via the GCC compiler on a Linux system.
We performed the steps and commands mentioned in this article on an Ubuntu 20.04 LTS system, but it works exactly the same on other versions like Ubuntu 18.04 or distributions like Debian 10.
We will use the Linux Terminal command line tool to compile a simple C program. To open Terminal, you can use Ubuntu Dash or the keyboard shortcut Ctrl + Alt + T.
Install essential build packages
To compile and run a C program, you need to have the essential packages installed on your system. Enter the following command as root on your Linux Terminal:
$ sudo apt-get install build-essential
You will be asked to enter the root password; the installation process will start after that. Make sure you are connected to the Internet.
Write a simple C program
After installing the essential packages, let’s write a simple C program. Open Ubuntu’s Graphical Text Editor and write or copy the following sample program into it:
#include
int main() {printf(” nA sample C program n n”); return 0;}
Then save the file with a .c extension.
Alternatively, you can write the C program through Terminal in gedit as follows:
$ gedit sampleProgram.c This will create a .c file where you can write and save a program.
Compile the C program with gcc Compiler
In your Terminal, type the following command to make an executable version of the program you wrote: Syntax: $ gcc [program Name].c -the name of the program
Make sure your program is located in your Home folder. Otherwise, you will need to specify the appropriate paths in this command.
run the program
O final step is to run the compiled C program. Use the following syntax to do this:
$ ./ Program name
You can see how the program runs in the example above by displaying the text we’ve written to print through it.
Final note
I hope you like the guide Guide: Run a C Compiler on Linux. In case if you have any query regards this article you may ask us. Also, please share your love by sharing this article with your friends.