f95 [options] files...
Here files… is one or more Fortran source file names ending in .f, .F, .f90, .f95, .F90, .F95, or .for; options is one or more of the compiler option flags. (Files with names ending in a .f90 or .f95 extension are “free-format” Fortran 95 source files recognized only by the f95 compiler.)
In the example below, f95 is used to compile two source files to produce an executable file named growth with runtime debugging enabled:
demo% f95 -g -o growth growth.f fft.f95
Note - You can invoke the Fortran compiler with either the f95 or f90 command.
New: The compiler will also accept source files with the extension .f03 or .F03. These are treated as equivalent to .f95 and .F95 and could be used as a way to indicate that a source file contains Fortran 2003 extensions.
2.2.2 Command-Line File Name Conventions, describes the various source file extensions accepted by the compiler.
After compilation, the object files, growth.o and fft.o, will remain. This convention permits easy relinking and recompilation of files.
If the compilation fails, you will receive a message for each error. No .o files are generated for those source files with errors, and no executable program file is written.
The suffix extension attached to file names appearing on the command-line determine how the compiler will process the file. File names with a suffix extension other than one of those listed below, or without an extension, are passed to the linker.
Table 2-1 Filename Suffixes Recognized by the Fortran Compiler
Fortran 95 free-format is described in 4.1 Source Language Features.
The Fortran compiler will accept multiple source files on the command line. A single source file, also called a compilation unit, may contain any number of procedures (main program, subroutine, function, block data, module, and so on). Applications may be configured with one source code procedure per file, or by gathering procedures that work together into single files. The Fortran Programming Guide describes the advantages and disadvantages of these configurations.
f95 supports two source file preprocessors, fpp and cpp. Either can be invoked by the compiler to expand source code “macros” and symbolic definitions prior to compilation. The compiler will use fpp by default; the -xpp=cpp option changes the default from fpp to cpp. (See also the discussion of the -Dname option).
fpp is a Fortran-specific source preprocessor. See the fpp(1) man page and the fpp README for details. It is invoked by default on files with a .F, .F90, F95, or .F03 extension.
The source code for fpp is available from the Netlib web site at
See cpp(1) for information on the standard Unix C language preprocessor. Use of fpp over cpp is recommended on Fortran source files.
You can compile and link in separate steps. The -c option compiles source files and generates .o object files, but does not create an executable. Without the -c option the compiler will invoke the linker. By splitting the compile and link steps in this manner, a complete recompilation is not needed just to fix one file, as shown in the following example:
Compile one file and link with others in separate steps:
demo% f95 -c file1.f (Make new object file) demo% f95 -o prgrm file1.o file2.o file3.o (Make executable file)
Be sure that the link step lists all the object files needed to make the complete program. If any object files are missing from this step, the link will fail with undefined external reference errors (missing routines).
Ensuring a consistent choice of compiling and linking options is critical whenever compilation and linking are done in separate steps. Compiling any part of a program with some options requires linking with the same options. Also, a number of options require that all source files be compiled with that option, including the link step.
The option descriptions in Chapter 3 identify such options.
Example: Compiling sbr.f with -fast, compiling a C routine, and then linking in a separate step:
demo% f95 -c -fast sbr.f demo% cc -c -fast simm.c demo% f95 -fast sbr.o simm.o link step; passes -fast to the linker
Any arguments on the command-line that the compiler does not recognize are interpreted as being possibly linker options, object program file names, or library names.
The basic distinctions are:
Unrecognized options (with a -) generate warnings.
Unrecognized non-options (no -) generate no warnings. However, they are passed to the linker and if the linker does not recognize them, they generate linker error messages.
demo% f95 -bit move.f <- -bit is not a recognized f95 option f95: Warning: Option -bit passed to ld, if ld is invoked, ignored otherwise demo% f95 fast move.f <- The user meant to type -fast ld: fatal: file fast: cannot open file; errno=2 ld: fatal: File processing errors. No output written to a.out
Note that in the first example, -bit is not recognized by f95 and the option is passed on to the linker (ld), who tries to interpret it. Because single letter ld options may be strung together, the linker sees -bit as -b -i -t, which are all legitimate ld options! This may (or may not) be what the user expects, or intended.
In the second example, the user intended to type the f95 option -fast but neglected the leading dash. The compiler again passes the argument to the linker which, in turn, interprets it as a file name.
These examples indicate that extreme care should be observed when composing compiler command lines!
f95 automatically creates module information files for each MODULE declaration encountered in the source files, and searches for modules referenced by a USE statement. For each module encountered (MODULE module_name), the compiler generates a corresponding file, module_name.mod, in the current directory. For example, f95 generates the module information file list.mod for the MODULE list unit found on file mysrc.f95 .
See the -Mpath and -moddir dirlist option flags for information on how to set the defaults paths for writing and searching for module information files.
See also the -use compiler option for implicitly invoking MODULE declarations in all compilation units.
For detailed information, see 4.9 Module Files.