| Howto Compiling C program and creating executable file under Linux / UNIX / *BSD |
|
How do I compile C program and creating executable file under Linux or UNIX operating systems?
A. You need GNU project C and C++ compiler for compiling C program and creating an executable file. Most Unix and Linux (*BSD) start their C compiler by the name cc. But you can use gcc command to compile program. First make sure you have gcc installed: Type the following command to verify that gcc is installed:
$ which gcc /usr/bin/gcc
Find out version of gcc: gcc (GCC) 4.0.3 20060212 (prerelease) (Debian 4.0.2-9) Copyright (C) 2006 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
To compile C program you need to use syntax as follows:
Consider following C program:
#include <stdio.h>
int main(void){
printf("My first C program\n");
return 0;
}
Compile C program first.c and create an executable file called first:
Execute program first: My first C program
However, both FreeBSD and Linux support direct make (GNU make
utility to maintain groups of programs) command on C program without
writing a make file. cc first.o -o first
Execute program first: |