Compaq Fortran
User Manual for
Tru64 UNIX and Linux Alpha Systems


Previous Contents Index

1.4.4 Other Compilers

You can compile and link multilanguage programs using a single f90 command.

The f90 command recognizes C or Assembler program files by their file suffix characters and passes them to the cc driver and compiler for compilation. Before compilation, cc applies the cpp preprocessor to files that it recognizes, such as any file with a .c suffix, and passes appropriate files to other compilers or the assembler.

Certain options passed to cc are passed by cc to the ld linker.

1.4.5 Linker (ld)

When you enter an f90 command, the ld linker is invoked automatically unless a compilation error occurs or you specify the -c option on the command line. The linker produces an executable program image with a default name of a.out .

The ld linker provides such primary functions as:

For more information, see ld(1) and your operating system's programmer's guide.

1.5 Program Development Stages and Tools

This manual primarily addresses the program development activities associated with implementation and testing phases. For information about topics usually considered during application design, specification, and maintenance, see your operating system documentation, appropriate reference pages, or appropriate commercially published documentation.

Table 1-1 lists and describes some of the software tools you can use when implementing and testing a program:

Table 1-1 Main Tools for Program Development and Testing
Task or Activity Tool and Description
Manage source files Use rcs or sccs to manage source files. For more information, see the Compaq Tru64 UNIX Using Programming Support Tools or the appropriate reference page.
Create and modify source files Use a text editor, such as vi or emacs . For more information, see your operating system documentation.
Analyze source code Use searching commands such as grep and diff . For more information, see the Compaq Tru64 UNIX Using Programming Support Tools and the appropriate reference page.
Build program (compile and link) You can use the f90 command to create small programs, perhaps using shell scripts, or use the make command to build your application in an automated fashion using a makefile. For more information on f90 , see Chapter 2 in this manual. For more information on make , see the make(1) reference page and the Compaq Tru64 UNIX Using Programming Support Tools.
Debug and Test program Use Ladebug (or dbx) to debug your program or run it for general testing. For more information on debugging, see Chapter 4 in this manual.
Analyze performance To perform profiling of code, use the prof and pixie (TU*X ONLY) programs. The f90 command option needed to use prof is -p (same as -p1 ).

To perform call graph profiling, use the gprof tool. The f90 command option needed to use gprof is -pg .

Related profiling tools include (TU*X ONLY) the use of feedback files and -cord .

For more information on profiling Fortran 90 code, see Chapter 5.

(TU*X ONLY) For more information on profiling parallel HPF applications with the pprof profiler, see the Compaq Parallel Software Environment documentation.

Install program
(TU*X ONLY)
Use setld and related commands such as tar . For more information, see the Compaq Tru64 UNIX Using Programming Support Tools.

To view information about an object file or an object library, use the following shell commands:

For more information on these commands, see the appropriate reference page or the operating system's programmer's guide.

To perform other program development functions at various stages of program development:

For More Information:


Chapter 2
Compiling and Linking Compaq Fortran Programs

As you read this chapter, remember that the f90 command invokes the Compaq Fortran compiler on Tru64 UNIX Alpha systems while the fort command invokes the Compaq Fortran compiler on Linux Alpha systems. This chapter uses the f90 command to indicate invoking the Compaq Fortran compiler on both systems, so replace this command with fort if you are working on a Linux Alpha system.

Also, remember that the cc command invokes the Compaq C compiler on Tru64 UNIX Alpha systems while the ccc command invokes the Compaq C compiler on Linux Alpha systems. This chapter uses the cc command to indicate invoking the Compaq C compiler on both systems, so replace this command with ccc if you are working on a Linux Alpha system.

This chapter provides information on the following topics:

For detailed information on f90 and fort command options, see Chapter 3.

2.1 The f90 Command: Files and Options

You should almost always use the f90 command to invoke both the Compaq Fortran compiler and the ld linker.

To link one or more object files created by the Compaq Fortran compiler, you should use the f90 command (instead of the ld command), because the f90 command automatically references the appropriate Compaq Fortran Run-Time Libraries when it invokes ld .

When you create your source files using a text editor, use file name suffix conventions expected by the f90 command, as described in Section 2.1.1.

2.1.1 File Suffixes and Source Forms

When creating a source file, choose the file name suffix appropriate for the source form (fixed or free). The f90 command recognizes certain source file suffixes as Fortran 95/90 source files.

Table 2-1 shows the recognized Fortran 95/90 source file suffixes.

Table 2-1 File Suffixes Recognized as Fortran 95/90 Source Files
Suffix Description
.f90 Identifies Fortran 95/90 files in free source form passed to the Compaq Fortran compiler.
.F90 Identifies Fortran 95/90 files in free source form passed to the cpp preprocessor and then compiled by the Compaq Fortran compiler.
.f , .for Identifies Fortran files in fixed (or tab) source form passed to the Compaq Fortran compiler but not preprocessed by cpp .
.F , .FOR Identifies Fortran files in fixed (or tab) source form passed to the cpp preprocessor and then compiled by the Compaq Fortran compiler.

Except for .F , .FOR , and .F90 files, preprocessors are not automatically run before Compaq Fortran compilation. To request that the cpp preprocessor be run before compilation, specify the -cpp option.

You can specify the source file form for all Fortran files on an f90 command line by using the -free option or -fixed option.

Table 2-2 shows other file name suffixes.

Table 2-2 Other File Name Suffixes
Suffix Description
Library and Object Files
.a Identifies archive object libraries passed to cc , which are in turn passed to ld . All routines in the specified object library are searched during linking to resolve external references.
.o Identifies object files passed to ld .
.so Identifies shared object libraries passed to cc , which are in turn passed to ld . All routines in the specified object library are searched during linking to resolve external references.
Compaq Fortran Module Files
.mod Identifies Fortran 95/90 module files created by the Compaq Fortran compiler. You do not create a .mod file directly and cannot specify a .mod file on the f90 command line (see Section 2.1.4).
Other Source Files
.c Identifies C language source files passed to the C compiler driver cc or ccc , which performs additional command line parsing before invoking the C preprocessor (via the command cpp ) and the C language compiler.
.i , .i90 Identifies intermediate files passed from cpp to the Compaq Fortran compiler. The .i or .i90 files are usually created by using the f90 options -P or -K (keep intermediate file) and -cpp (invoke cpp ).
.s Identifies assembler files passed to cc or to ccc .

To specify libraries (in addition to those automatically searched by the f90 command), you can also use an f90 command option, such as the -lstring option.

Source file suffixes used by other Compaq languages include: Ada ( .ada ), C++ ( .cxx , .cc , .C ), COBOL ( .cob ), Pascal ( .p ) (TU*X ONLY), and PL/I ( .pli ) (TU*X ONLY).

For More Information:

On source forms and source coding guidelines that allow the same source file to be used with multiple source forms, see the Compaq Fortran Language Reference Manual.

2.1.2 Format of the f90 and fort Commands

The f90 command (on Tru64 UNIX systems) has the following general form:

f90 [--options [args]]... filename [filename]... [--options [args]]...

The fort command (on Linux systems) has the following general form:

fort [--options [args]]... filename [filename]... [--options [args]]...

--options [args]

Indicates either special actions to be performed by the compiler or linker, or special properties of input or output files. For details about command line options, see Chapter 3.

If you specify the -l string option (which indicates libraries to be searched by the linker) or an object library file name, place it after the file names and after other options.

filename

Specifies the source files containing the program units to be compiled and other files to be used by the Compaq Fortran compiler. The file name has a suffix that indicates the type of file used, such as .f90 or .f (see Section 2.1.1).

If you omit the suffix or it is not one of the preceding types recognized by the f90 command, the file is assumed to be an object file and is passed directly to the linker.

An example f90 command line follows:


% f90 -v test.f calc.o -lmnd

This command specifies the following:

2.1.3 Specifying Files and Options

You can use an f90 command to specify multiple options and multiple file names, separated by spaces. If appropriate, the file names can have a different suffix. The file name suffix can result in the following actions:

When a file is not in your current working directory, specify the directory path before the file name.

2.1.4 Creating and Using Module Files

Compaq Fortran creates module files for each module declaration and automatically searches for a module file referenced by a USE statement. A module file contains the equivalent of the module source declaration in a post-compiled, binary form.

2.1.4.1 Creating Module Files

When you compile a Compaq Fortran source file that contains module declarations, Compaq Fortran creates a separate file for each module declaration. The name declared in a MODULE statement becomes the base prefix of the file name and is followed by the .mod suffix.

For example, consider compiling a file that contains the following statement:


MODULE MOD1 

The compiler creates a post-compiled module file mod1.mod in the current directory. An object file is also created for the module.

Compiling a source file that contains multiple module declarations will create multiple module files, but only a single object file. If you need a separate object file for each module, place only one module declaration in each file.

If a source file does not contain the main program and you only need to create module files, specify the -c option to prevent linking.

An object file is not needed if there are only INTERFACE or constant (PARAMETER) declarations. It is needed for all other types of declarations including variables.

2.1.4.2 Using Module Files

Once they are created, you can copy module files into an appropriate shared or private directory. You reference a module file specifying the name in a USE statement (use association). For example:


 USE MOD1 

When selecting a directory location for a set of module files, consider how your application will be built, including:

To locate module files specified in USE statements, the Compaq Fortran compiler searches the following directories:

Suppose you need to compile a main program proj_main that contains one or more USE statements. To request that the compiler look for module files in the additional directories /usr/proj_module/f90 and then /usr/common/f90 (after looking in the current directory), type the following command line:


% f90 proj_main.f90 -I/usr/proj_module/f90 -I/usr/common/f90

If you specify multiple directories, the order of -Idir options on the f90 command line determines the directory search order.

You cannot specify a .mod file directly on the f90 command line.

Module nesting depth is unlimited. If you will use many modules in a program, check the process and system descriptor limit (see Section 1.1).

For More Information:

2.1.5 The INCLUDE Statement and Using Include Files

You can create include files with a text editor. If needed, you can copy include files to a shared or private directory.

When selecting a directory location for a set of include files or text libraries, consider how your application is to be built, including:

Include files have a file name suffix like other Compaq Fortran source files (such as .f90 , .f , and .for ). Use an INCLUDE statement to request that the specified file containing source lines be included by the compiler in place of the INCLUDE statement.

The INCLUDE statement has the following form:

INCLUDE 'name'
INCLUDE 'name.typ'

You can also include a file with a pathname specified with the following form:

INCLUDE '/pathname/name'
INCLUDE '/pathname/name.typ'

If you specify the -vms option, you can specify /LIST or /NOLIST after the file name. For example:

INCLUDE '/pathname/name/LIST'
INCLUDE 'name.f90/NOLIST'

You can also specify the -show include option to request that source lines from included files appear in the listing file (see Section 3.73).

When the INCLUDE Statement Specifies a Pathname

Specifying pathname limits the directory searching done for the named file. For example, pathname might specify a directory /usr/users/proj for the file named common_proj.f90 :


 INCLUDE 'usr/users/proj/common_proj.f90' 

If a directory pathname is specified, only the specified directory is searched.

When the INCLUDE Statement Omits a Pathname

When the INCLUDE statement omits a pathname, one or more directories are searched for the specified file name.

To locate include files specified in INCLUDE statements without a pathname, the Compaq Fortran compiler searches directories in the following order:

  1. The directory that the source file resides in ( -vms option was omitted) or the current process default directory ( -vms option was specified)
  2. Each directory specified by one or more -Idir options.
  3. The /usr/include directory (unless the -noinclude option was specified)

Compaq Fortran allows you to use multiple methods to specify which directories are searched for include files:


Previous Next Contents Index