NOTE: For libF90, libU77, and libIO77(Itanium® only), archive libraries are selected by default (see +sharedlibF90, +sharedlibU77, and +sharedlibIO77options).

To force the linker to select archive libraries, specify the -Wl,-a,archiveoption on the

f90command line. f90passes the arguments to the -Wloption (-aand archive) to the linker. This option must appear before the names of any libraries also specified on the command line. The following command line compiles prog.f90and links it with the archive versions of the default libraries as well as with the math library (as specified by the-lmoption):

$ f90 -Wl,-a,archive prog.f90 -lm

For information about the linker’s -aoption, see the ld(1) man page. For more information about shared libraries, see “Creating shared libraries” (page 59).

Library search rules

When you use the -loption to specify the name of a library, the linker searches for the library in the directories specified by the LPATHenvironment variable. The f90command sets this variable so that the linker looks first in /opt/fortran90/lib, then in/usr/lib . You can specify another directory to search by settingLPATHyourself; see “LPATH environment variable” (page 65).

Alternatively, you can use the -Ldirectoryoption to direct the linker to search directorybefore it looks anywhere else to resolve references. For example, the following command line:

$ f90 -L/my_libs prog.f90 -lstuff

causes the linker to search for libraries (including libstuff.sl and libstuff.a), starting with the directory /my_libsand then looking in /opt/fortran90/lib and /usr/lib.

Special-purpose compilations

The default behavior of the HP Fortran compiler has been designed to handle typical compilations. Most applications should require no more than a few of the f90options to compile successfully (see Table on page 25 for a list of commonly used options).

However, the compiler can also meet the needs of more specialized compilations. This section explains how to use the f90command for the following purposes:

To compile programs that contain Fortran modules.

To compile programs that will execute on different PA-RISC machines.

To create object files for shared libraries.

To process source files that contain C preprocessor directives.

To create demand-loadable programs.

To create shareable executable programs.

To compile 32-bit programs in 64-bit mode.

Compiling programs with modules

One of the features of standard Fortran is the module, a program unit that facilitates shared access to data and procedures. Modules are fully described in the HP Fortran Programmer’s Reference.

A benefit to using modules is that they provide interface information to the compiler, allowing it to catch mismatch errors between (for example) dummy arguments and actual arguments. When the HP Fortran compiler processes a file that defines a module, it generates a .modfile with the interface information. Later, when the compiler processes a file that uses the module, it reads the .modfile and checks that module entities that are referenced in the using file correctly match the information in the.mod file.

54 Compiling and linking