In this blog we are discussing about the first LINUX program – printing
‘HELLO’ on screen – using GCC. Programming in Linux is same as programming in
Windows TC. For this, start your Linux, open user’s “Home Folder”. Home folder
is accessed from ‘Places’ menu from Left corner of Upper Taskbar or from left
sidebar on Desktop. Home folder name can be your login name. Then right click
on empty space, you will get property menus- Create Folder, Create Documents,
Arrange items, etc… Select ‘Create Documents à Empty file’ menu. It will create an empty file
with name ‘new file’; rename it with ‘hello.c’ (small letters compulsory). Then
you can write your C code in it. Let C code is –
#include<stdio.h>
int main()
{
printf(“\n\n HELLO
\n\n”);
return 0;
}
Now,
In TC (Windows), we are including “conio.h”
header file in C code. Also we are using clrscr(), getch() functions. But in
Linux, we are not using it. It has a reason. Because “conio.h” header file is
not an ANSCII approved header file. Linux GCC has only ANSCII approved header
files and include only them.
If you try to include them in C code, then Terminal (GCC) will give
error that ‘conio.h file can’t be included’.
Now, close the “hello.c” file. Open Linux Terminal, it is in
“Application” menu in left corner of upper taskbar or from left sidebar.
Navigate terminal to “hello.c” file directory (if necessary, using cd command).
Then type one of the following commands.
1)
gcc hello.c
If
C-code is syntactically correct, then on Terminal there will not be any error
message and you will get “a.out” executable file in same directory otherwise
prints errors of C-code with line no. on Terminal.
2)
gcc hello.c –o hello.ext
It
is same is first command but it creates “hello.ext” executable file except
“a.out” in same directory. You can give any filename and extension in command.
3)
gcc hello.c –Wall –Werror –o
hello.ext
It
is same is first command but if C-code contain any warnings then these will be
printed on Terminal as errors and if C-code is syntactically correct then it
creates “hello.ext” executable file in same directory.
Now,
you got “a.out” or “hello.ext” executable file on directory. For running it on
Terminal, you have to give a command like-
./a.out OR
./hello.ext
a.out
or hello.ext file gets executed and you will get result on Terminal screen.
PICTORIAL PROCEDURE IS AS FOLLOWS =