You need GNU C and C++ compiler for compiling C program and creating an executable file. You can use gcc command to compile program.
First make sure you have gcc installed:
OutputCode:which gccok u have C compiler in ur box.. [ if u don't have install gcc ]Code:/usr/bin/gcc
To compile C program you need to use syntax as follows:Code:gcc -o program-output program.c
Now Write Our First C Program Under Linux / UNIX
Use a text editor such as vi or gedit to create a C program called first.c:Type the following lines (program):Code:$ vi first.cHow Do We Compile Our Program?Code:#include <stdio.h> int main(void){ printf("My first C program\n"); return 0; }
To compile C program first.c, and create an executable file called first, enter:ORCode:$ gcc -o first first.cTo execute program first, enter:Code:$ cc -o first first.cOutput:Code:$ ./firstCode:My first C program
However, both FreeBSD and Linux support direct make command on C program without writing a make file. Remove, first program using the rm command:
Output:Code:$ rm first $ make firstExecute program first:Code:cc first.o -o firstCode:$ ./first
Last edited by TuxRacer; 02-18-2010 at 01:41 AM.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks