next up previous contents index
Next: Important Platform Dependant Up: Software Development Previous: Compiling and Linking

Compile, Link, Run

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 gif use:

 
               		  f77  hello.f

If 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.c

a.out

If your source is divided among separate files, simply specify all files in the compile command:
 
               		  f77  main.f func1.f ... funcn.f

The -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.f

The -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.f

f77 main.f func.o



Alan Silverman
Wed Apr 12 16:54:02 METDST 1995