What is GFortran?

GNU Fortran is a part of GCC, the GNU Compiler Collection. GCC consists of a collection of front ends for various languages, which translate the source code into a language-independent form called GENERIC. This is then processed by a common middle end which provides optimization, and then passed to one of a collection of back ends which generate code for different computer architectures and operating systems. Additional information regarding what GFortran is can be found here.

This short tutorial is a guide to help familiarize you with writing a simple Hello World program using the GFortran compiler.

Install gFortran

paru -S gcc-fortran

Check to see if you have gfortran installed.

To check whether you have gfortran already installed type in the command:

(base) [yanboyang713@archlinux ~]$ which gfortran
/usr/bin/gfortran

If nothing is returned then gfortran is not installed.

Let’s create our first program

Note: It is important to include the ‘.f’ after every file that you wish to compile using the gfortran compiler.

vim fortran.f
program helloworld
 
print *, “Hello World”
 
end program helloworld

compiling the file

gfortran fortran.f

Run

./a.out

Reference List

  1. https://laptops.eng.uci.edu/engineering-software/programming-basics/gfortran-hello-world
  2. https://ubuntu-archive-team.ubuntu.com/madison.cgi?package=gfortran&a=&c=&s=