In this tutorial, I am going to show you how to write and compile C Program using Code-blocks on Linux system. We have already seen this for Windows system, also we have seen how to write and compile C Program using Linux command line. Here I am using Code-blocks 20.03 on Ubuntu 20.04 Linux system to demonstrate this tutorial, however, it will work for most of the Linux distributions.
Let's get started
Starting Code-blocks on Ubuntu 20.04
Though applications can be started in many ways on Ubuntu desktop , the simple method is, click on the nine grid button at the bottom of the dash and all the applications will be shown, after that just click on Code-blocks icon to start it. You can also use Super key to list out all of the applications.
And here is the Code-blocks 20.03 interface on Ubuntu 20.04 Linux system.
SECTION 1
Creating folder and an empty C Program file
Step 1.
Go to File > New > ,then click on File.
Step 2.
A new window will pop up, select C/C++ source in Category section and then click on Go button.
Step 3.
In the new pop up window, check the tick box and then click on Next button.
Step 4.
Now in this pop up window, click on ‘C’ in the selection window, and then click on Next button.
Step 5.
In this pop up window,click on the button near the field Filename with full path: to create a folder in your Home directory on Linux system to save your C Program files.
Step 6.
Now here in this pop window, click on the folder button to create a new folder, give a name to it and then click on the Create button.
Step 7.
Now you are in the folder that you have just created, give a filename to your C Program file before the Name field with ‘.c’ extension e.g. ‘helloworld.c’ and then click on Save button.
Step 8.
First section of creating folder and C Program file is completed here. Now you can use this folder to save as many program files as you want. Just need to select this folder and create another program file. Click on Finish button.
SECTION 2
Write Compile and Run a C Program
Step 1.
Now we are inside the Code-blocks IDE with an empty file where we can write a C Program.
Step 2.
Just write any C Program here. I have wrote a C Program to display ‘Hello World’ string on the screen. After you finish writing your C Program, first you have to save the program using the third icon like floppy below file menu, and then click on the Green triangled button to compile and run the C Program. See in below screenshot.
After writing the program you can save the program file in three ways
1) by pressing ‘Ctrl+S’ keys from keyboard, or
2) by clicking on the third icon on ribbon (floppy drive icon), or
3) Go to File > then click on Save file.
Step 3.
Now you will see a new pop up window, click on Yes button to build the C Program.
In this process first the C Program will be compiled, if it is having any syntax errors, those will be shown in error log window at the bottom of Code-blocks IDE.
You have to rectify those errors and save the file and do this step again until you get zero errors. When your program will be with zero errors, it will be compiled and an executable C Program output file will be created. Code-blocks will run C Program executable file automatically in this process. Then you will see C Program output in command window.
In below screenshot, you see the C Program output in command window. Here you see your C Program (source code), your C Program Output and the Error Log window.
This is the simple and fast method to compile and run a C Program. But you can check different options by going in the 'Build' menu to complile and run a C program step by step, exlplore it.
Step 4.
After you have done using Code-blocks, close the application by going to File menu and then click on Quit or you can use keyboard shortcut Ctrl+Q.
Step 5.
You will see three files created in your C Programs folder after C Program compilation process, those files are, first is your C Program executable file (.exe), second is your C Program Souce code file (.c) and third is your C Program Object file (.obj), check these files.
Conclusion
In this way we have seen in this tutorial all the steps of how to write and compile C Program using Code-blocks 20.03 IDE on Ubuntu 20.04 Linux system. First we created a folder in your Home directory on Linux system and then created an empty C program file.
After that we wrote a simple C Program to display "Hello World" string on display. Then we compiled that C Program using in Code-blocks and checked the program output.
Comments
Post a Comment