HP Fortran Programmer's Guide (B3908-90031; September 2011)

Compiling and linking
Linking HP Fortran programs
Chapter 2 81
When the linker finds a reference in your program to a name that is not defined in the program (for example,
the DOT_PRODUCT intrinsic), it looks to resolve it in the default libraries. If it cannot find the name in the
default libraries, the link will fail unless the command line specifies additional, nondefault libraries. This
section discusses how to link to nondefault libraries (including shared libraries) and library search rules.
Linking to nondefault libraries
The -l option enables you to specify other libraries for linking, in addition to the default libraries listed in
Table 2-14. The syntax for this option is:
-lx
where x is a sequence of characters that completes a library name of the form /lib/libx.a or
/usr/lib/libx.a. For example, -lm specifies the math library, /usr/lib/libm.a. (The .a extension
indicates an archive library. You can also link to shared libraries, which have the .sl extension; see
“Linking to shared libraries” on page 83.)
The -l option is order-sensitive: when the linker finds a reference in an object file that it cannot resolve in
the default libraries, it searches the libraries (if any) specified after the file on the command line. For
example, the following command line tells the linker to look for unresolved references in the math library as
well as the default libraries:
$ f90 prog.f90 -lm
You can also link a library to your program by specifying its name after the name of the source file that
references it, as follows:
$ f90 prog.f90 /usr/lib/libm.a
This form of the command line is useful for linking libraries that do not conform to the naming convention
required by the -l option or that reside in a directory other than /lib or /usr/lib. As with the -l option,
the library name must follow the name of the source file that references it. For example, the following
command line links prog.f90 with the library my_routines, both of which reside in the current working
directory:
$ f90 prog.f90 my_routines
If your program calls routines in a library but the linker is unable to resolve the references, compile with the
-Wl,-v option. The f90 command passes -v to the linker, causing it to process in verbose mode. The
verbose information includes:
/opt/fortran90/lib/hpux[32|64]/li
bF2003.a
Archive library for Fortran 2003 standard features
Table 2-14 Libraries linked by default on Itanium (Continued)
Library Contents