Thursday, February 20, 2014

Using GCC on any version of Ubuntu via Terminal

  1 comment
Using C++ on any version of Ubuntu is easy. I firstly kept searching for an external complier but later I knew the better use of GCC via terminal.
I found some difference in using header-file and program ending codes when compared to Turbo C or Dev C++ running in windows.

Here is the steps and an example programe.


I have shown example of entering and displaying multiplication table of certain number upto 10 times. I used Gedit as a Text Editor to write C codes.
 
Saving the file follows the universal rule as in any other programe, file-name should follow “.c” extension.
I wrote following code and saved as mul.c in Desktop folder.

Open Terminal.

Go to Desktop by typing “cd Desktop” (case sensitive)

Then type “/usr/bin/gcc mul.c -o mul” to compile, Here, mul.c is the file name saved in desktop using gpedit. And mul is the name of the executable file created after compile is over.

Error free compiling process creates a new line and blinking cursor comes at the end. It also creates an executable file in the same directory.


To execute the program, “./mul” is needed. Again here, mul is the file-name which was created after compiling in previous step.

I entered digit 5 for the calculation as shown in the figure above.
Enjoy!

1 comment :

Comments