Examples

  1. Compile (and link) the tempconv.f FORTRAN program source file using g77.
    1. Open a Secure Shell terminal window.
    2. Change to the directory of your source file.
    3. Type g77 tempconv.f and press Enter.

    If there are no error messages, you should find a new file named a.out in the same directory as your source file. This indicates that you were able to successfully compile your source code into object code and to then link the object code into a an executable file named a.out.

    If there are compile-time errors, you must fix each error before a valid executable can be be built. Each error includes a message and a line number and location of where the error was recognized.

    Note: Often compile-time errors aren't recognized until lines later in the source code. So you should plan on fixing something earlier in the source code rather than just trying to fix the line that produced the error.

  2. When a program has many source files, it may be necessary to split the compiling and linking into two steps. Use the -c to just compile your source code files without linking them into an executable.

    For example, to compile the source code of a tempconv that uses two separate function definition files, ftoc.f and ctof.f.

    g77 -c ftoc.f ctof.f tempconv.f

    This use of g77 translates each source file into object code, but does not attempt to link them together into a final executable program file. See the next example for the command to link them to a named executable.

  3. Computers don't run object directly. The object code files must be linked into a final executable program file. The same program named g77 can complete this step also.

    For example, to link the object code of the previous example tempconv.o and ftoc.o and ctof.o and build an executable file:

    g77 ftoc.o ctof.o tempconv.o

    This use of g77 links the object code files together and builds an executable file named, a.out.

  4. To name the final executable file with a different name, use the -a switch and include a name for the executable.
    g77 -a myTempConv ftoc.o ctof.o tempconv.o

    This use of g77 links the object code files together and builds an executable file named, myTempConv.