Compiling and Running C Programs
You can compile your program with the gcc command. The output of the compiler
command, i.e., the executable program is stored in the [Link] file by default. To
compile a source file titled program.c, type:
$ gcc program.c
You can run the executable program generated by this command by typing./[Link] and
hitting the <Enter> key, as shown in the following session.
$ ./[Link]
[ ... program output ... ]
You can store the executable program in a specific file by using the –o option. For
example, in the following session, the executable program is stored in the
assignment file.
$ gcc program.c –o assignment
The gcc compiler does not link many libraries automatically. You can link a library
explicitly by using the –l option. In the following session, we are asking the
compiler to link the math library with our object file as it creates the executable
file.
$ gcc program.c –o assignment -lm
$ assignment
[ ... program output ... ]