Although the name of the compiler and recommended options may differ from platform to platform, all Unix compilers function in essentially the same way as illustrated in the simple examples below.
To create an executable program, you compile a source file containing a main
program. For example, to compile a Fortran program named
hello.f
use:
f77 hello.fIf no errors occur, the compiler creates an executable file named a.out in the current working directory. Similarly, to compile and then run a C program use:
cc hello.cIf your source is divided among separate files, simply specify all files in the compile command:a.out
f77 main.f func1.f ... funcn.fThe -o name option causes the compiler to name the output file name instead of a.out. For example, to compile a Fortran program hello.f and name the resulting executable hello use:
f77 -o hello hello.fThe -c option suppresses the link-edit phase. The compiler generates an object file with the extension .o for each input file and not the a.out file. This is useful when compiling source files that contain only subprograms, which can be linked later with other object files. The resulting object files can then be specified on the compiler command line:
f77 -c func.ff77 main.f func.o