Compiling Fortran and C programs



Last revision August 4, 2004

Table of Contents:
  1. cc is the C language compiler and linker
  2. f77 is the Fortran language compiler
  3. ld is the basic loader or linker program
  4. Running your executable programs

Running your executable programs

The cc and f77 compilers/linkers create the final executable file with the correct permissions to be run directly as a program. You start the program by simply giving its name as a command, just as you would any of the system programs, such as ls or more.

The only problem is to make sure that the shell can find your program. The shell checks the directories listed in the PATH environment variable (set by the set path command in your .cshrc file) to find programs to run. This PATH usually includes the current directory . and a subdirectory of your home directory named bin, plus all the system directories.

Actually, the shell reads the PATH list only once -- when it starts -- and creates an index in memory of all files located there. With the exception of the current directory ., it only checks its list in memory, not the actual directory on disk, when looking for the program that you want to run.

So if you make a new program, and put it in your ~/bin directory, for example, the shell will not find it unless you tell the shell to rebuild its index of programs in memory. You do this by giving the built-in shell command rehash.

You can also explicitly specify the location of a program on disk, for example, ~joe/morgan. Then the shell can find it regardless of the PATH setting.

It is a good idea to use the -o name option to the cc or f77 commands to give your program a useful name. Otherwise the final executable file will simply be called a.out. The pangea big jobs policy says that only test programs should have the name a.out, and they should not run very long. In fact, an automatic system program on pangea will kill any process with the name a.out if it uses more than 15 minutes of CPU time.

Watch your program carefully when you run it for the first time! Don't just start it and leave for a day - it could have a bug that causes it to loop infinitely, consuming CPU time. You are strongly urged to learn to use the dbx symbolic debugger, compile your program initially with the -g option, and run it the first time under control of the debugger so you can see exactly what is happening. Also, Fortran users should compile the test version with the -u and -C options to catch common typographical errors in specifying variable names and array subscripts.