Linux is very popular OS in these days mostly among programmers and other sectors. We discuss how to compile and execute C program in Linux environment. Linux provide default C compiler which is GCC (GNU Compiler Collection). We use this compiler to compile and execute our C program. For this, we have to follow the following steps:
- Write a simple C program using any text editor and save it.
- Compile the program with this command: gcc filename.c -o outputfilename
- Execute the program with the command: ./outputfilename
In step 2 gcc species a compiler we are going to use, filename.c is the sour code file, -o species the output file name and outputfilename is our output file name which is used to execute out program. We don't need to provide file extension for the output file name. In some cases we need to link to linker, in such cases we need to give extra parameter while compiling the program.
eg: gcc filename.c -o outputfilename -lm
Here -lm is extra parameter that tells the compiler to link to the linker.
eg: gcc filename.c -o outputfilename -lm
Here -lm is extra parameter that tells the compiler to link to the linker.
No comments:
Post a Comment