Monday, June 7, 2010

How to run a C program in Linux

To run a C program in Linux:

1. Verify the gcc program is installed on system
gcc --version

2. Write a test program
cat > mycprog.c
#include <stdio.h>
     int main (void)
        { printf ("My C Program \n");
            return 0;
         }

Save the program using ^D

3. Compile the C program
gcc mycprog.c

The output will be a.out compile file. Now run the compiled file by typing
./a.out

Output of a C program can be renamed
e.g.;
gcc mycprog.c -o firstprog

Now execute as
./firstprog

  

No comments:

Post a Comment