Once you finish writing your source code, the next step is always its compilation which generates the executable code. To compile your code, type the following line in your terminal:
g77 fact.f -o fact.exeThis causes that
g77
compiler reads the Fortran source code fort.f
, searches for
errors in this file, translates it to the machine language and produces the executable file
fact.exe
(on Mac, you are free to avoid the extension .exe
). Although it should not be
the case here, you can sometimes encounter warnings and/or error messages produced by the
compiler. If it finds errors in your source code, it also tells you what is wrong. Your task is then
to go back to Emacs, find the error and fix it. Remember, the executable code is not produced unless
the compilation finishes without errors.
If you correctly typed the program above, the current directory should now contain the executable
file fact.exe
. Check this by typing dir
(on Windows) or ls
(on Mac). Your
program can now be executed by writing fact
(on Windows) or ./fact
(on Mac) in your
command-line terminal. The output of this program should look exactly as follows:
Factorial of 5 is 120
Roman Gröger (2015-09-23)