< Back

Error messages compiling Fortran source code using gfortran on Linux


Problem:

I get error messages when I try to compile Fortran source code using gfortran on Linux, even though I installed all the necessary “build-essential” gfortran libraries.
Unable to compile Fortran source code using gfortran on Linux.

Solution:

If you are getting error messages when compiling the Fortran source code consider the following.
First, the order of calls in the command line is important.  Using Tecplot’s simtest.f90 Fortran source code as an example, use the following order to properly compile:
gfortran -fcray-pointer simtest.f90 libtecio.a -lstdc++
Another method is to use two commands to resolve the libraries and symbols:
gfortran -c -fcray-pointer simtest.f90 -I../../tecsrc -I$(TECHOMEDIR)
g++ simtest.o -L$(GFORTRANHOME) -lgfortran ../../libtecio.a -o simtest
Where TECHOMEDIR is your Tecplot home directory and GFORTRANHOME is found by typing:
locate gfortran, and look for the entry that has libgfortran.so.xxx
The above can also be saved to a Makefile, and then the Makefile can be run to compile the Fortran source code. An example is below.
———–
# Customize TECHOMEDIR and GFORTRANHOME as needed
TECHOMEDIR=/tecplot/include
GFORTRANHOME=/usr/lib/x86_64-linux-gnu
EXE=simtest
$(EXE):
gfortran -c -fcray-pointer simtest.f90 -I../../tecsrc -I$(TECHOMEDIR)
g++ simtest.o -L$(GFORTRANHOME) -lgfortran ../../libtecio.a -o simtest
clean:
rm -f $(EXECUTABLE)
———–