GNU Fortran, or g77
, is designed initially as a free replacement
for, or alternative to, the UNIX f77
command.
(Similarly, gcc
is designed as a replacement
for the UNIX cc
command.)
g77
also is designed to fit in well with the other
fine GNU compilers and tools.
Sometimes these design goals conflict--in such cases, resolution often is made in favor of fitting in well with Project GNU. These cases are usually identified in the appropriate sections of this manual.
As compilers, g77
, gcc
, and f77
share the following characteristics:
gdb
).
ld
command.
However, the g77
and gcc
commands, as with most compiler commands, automatically
perform the linking step by calling on ld
directly, unless asked to not do so by the user.)
How these actions are performed is generally under the control of the user. Using command-line options, the user can specify how persnickety the compiler is to be regarding the program (whether to diagnose questionable usage of the language), how much time to spend making the generated machine code run faster, and so on.
g77
consists of several components:
gcc
command, which also might be
installed as the system's cc
command.
(In many cases, cc
refers to the
system's "native" C compiler, which
might be a non-GNU compiler, or an older version
of gcc
considered more stable or that is
used to build the operating system kernel.)
g77
command itself, which also might be installed as the
system's f77
command.
libg2c
run-time library.
This library contains the machine code needed to support
capabilities of the Fortran language that are not directly
provided by the machine code generated by the g77
compilation phase.
libg2c
is just the unique name g77
gives
to its version of libf2c
to distinguish it from
any copy of libf2c
installed from f2c
(or versions of g77
that built libf2c
under
that same name)
on the system.
The maintainer of libf2c
currently is
dmg@bell-labs.com.
f771
.
Note that f771
does not generate machine code directly--it
generates assembly code that is a more readable form
of machine code, leaving the conversion to actual machine code
to an assembler, usually named as
.
gcc
is often thought of as "the C compiler" only,
but it does more than that.
Based on command-line options and the names given for files
on the command line, gcc
determines which actions to perform, including
preprocessing, compiling (in a variety of possible languages), assembling,
and linking.
For example, the command gcc foo.c
drives the file
foo.c
through the preprocessor cpp
, then
the C compiler (internally named
cc1
), then the assembler (usually as
), then the linker
(ld
), producing an executable program named a.out
(on
UNIX systems).
As another example, the command gcc foo.cc
would do much the same as
gcc foo.c
, but instead of using the C compiler named cc1
,
gcc
would use the C++ compiler (named cc1plus
).
In a GNU Fortran installation, gcc
recognizes Fortran source
files by name just like it does C and C++ source files.
It knows to use the Fortran compiler named f771
, instead of
cc1
or cc1plus
, to compile Fortran files.
Non-Fortran-related operation of gcc
is generally
unaffected by installing the GNU Fortran version of gcc
.
However, without the installed version of gcc
being the
GNU Fortran version, gcc
will not be able to compile
and link Fortran programs--and since g77
uses gcc
to do most of the actual work, neither will g77
!
The g77
command is essentially just a front-end for
the gcc
command.
Fortran users will normally use g77
instead of gcc
,
because g77
knows how to specify the libraries needed to link with Fortran programs
(libg2c
and lm
).
g77
can still compile and link programs and
source files written in other languages, just like gcc
.
The command g77 -v
is a quick
way to display lots of version information for the various programs
used to compile a typical preprocessed Fortran source file--this
produces much more output than gcc -v
currently does.
(If it produces an error message near the end of the output--diagnostics
from the linker, usually ld
--you might
have an out-of-date libf2c
that improperly handles
complex arithmetic.)
In the output of this command, the line beginning GNU Fortran Front
End
identifies the version number of GNU Fortran; immediately
preceding that line is a line identifying the version of gcc
with which that version of g77
was built.
The libf2c
library is distributed with GNU Fortran for
the convenience of its users, but is not part of GNU Fortran.
It contains the procedures
needed by Fortran programs while they are running.
For example, while code generated by g77
is likely
to do additions, subtractions, and multiplications in line--in
the actual compiled code--it is not likely to do trigonometric
functions this way.
Instead, operations like trigonometric
functions are compiled by the f771
compiler
(invoked by g77
when compiling Fortran code) into machine
code that, when run, calls on functions in libg2c
, so
libg2c
must be linked with almost every useful program
having any component compiled by GNU Fortran.
(As mentioned above, the g77
command takes
care of all this for you.)
The f771
program represents most of what is unique to GNU Fortran.
While much of the libg2c
component comes from
the libf2c
component of f2c
,
a free Fortran-to-C converter distributed by Bellcore (AT&T),
plus libU77
, provided by Dave Love,
and the g77
command is just a small front-end to gcc
,
f771
is a combination of two rather
large chunks of code.
One chunk is the so-called GNU Back End, or GBE,
which knows how to generate fast code for a wide variety of processors.
The same GBE is used by the C, C++, and Fortran compiler programs cc1
,
cc1plus
, and f771
, plus others.
Often the GBE is referred to as the "gcc back end" or
even just "gcc"--in this manual, the term GBE is used
whenever the distinction is important.
The other chunk of f771
is the
majority of what is unique about GNU Fortran--the code that knows how
to interpret Fortran programs to determine what they are intending to
do, and then communicate that knowledge to the GBE for actual compilation
of those programs.
This chunk is called the Fortran Front End (FFE).
The cc1
and cc1plus
programs have their own front ends,
for the C and C++ languages, respectively.
These fronts ends are responsible for diagnosing
incorrect usage of their respective languages by the
programs the process, and are responsible for most of
the warnings about questionable constructs as well.
(The GBE handles producing some warnings, like those
concerning possible references to undefined variables.)
Because so much is shared among the compilers for various languages,
much of the behavior and many of the user-selectable options for these
compilers are similar.
For example, diagnostics (error messages and
warnings) are similar in appearance; command-line
options like -Wall
have generally similar effects; and the quality
of generated code (in terms of speed and size) is roughly similar
(since that work is done by the shared GBE).