Sunday, August 7, 2011

How to Compile C program in Linux

When I first started using the C language in linux, it seems stiff, but after a long time I was accustomed. In fact, I prefer to use linux for the C language than any other OS.
That should be done to create a program with C language in Linux include:


1. Create a script using a text editor program, can use gedit, kate, vi, nano, and so forth. example:


# include <stdio.h>
void main ()
{
print ("my C program on linux");
}
or
# include <stdio.h>
void main ()
{Print ("my C program on linux");}
2. Save the above script with the extension. "C", eg: "test.c"
3. Now go into the compilation. Log into the terminal, can use tombon "Ctrl + Alt + t" or by clicking Applications> Accessories> Terminal.
4. From the terminal, we go into the file storage directory in the script that created earlier, eg I save in the Document, then I go into the document with the command:

ananurdiana@ubuntu:~ cd Document
then typing the command C compiler, which is gcc (in the format "gcc-o nama_file_script nama_file_program"). For example:
ananurdiana@ubuntu:\Documents\ gcc test.c -o test
5. So when in the list, will appear a new file that can be executed or run.
ananurdiana@ubuntu:\Documents\ ls
ananurdiana@ubuntu:\Documents\ test.c    test
to run a program that was compiled, with command:
ananurdiana@ubuntu:\Documents\ .test
6. Then look at the programs that created earlier as below:
ananurdiana@ubuntu:\Documents\ My C program in linux
Thus making the C program in linux, it is very easy is not it!

readbud - get paid to read and rate articles

No comments:

Post a Comment