HP Fortran Programmer's Guide (March 2010)

Compiling and linking
Linking HP Fortran programs
Chapter 2 87
To force the linker to select archive libraries, specify the -Wl,-a,archive option on the f90
command line. f90 passes the arguments to the -Wl option (-a and 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.f90 and links it with the archive versions of the
default libraries as well as with the math library (as specified by the -lm option):
$ f90 -Wl,-a,archive prog.f90 -lm
For information about the linker’s -a option, see the ld(1) man page. For more information
about shared libraries, see “Creating shared libraries” on page 93.
Library search rules
When you use the -l option to specify the name of a library, the linker searches for the library
in the directories specified by the LPATH environment variable. The f90 command 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 setting LPATH yourself; see “LPATH environment
variable” on page 101.
Alternatively, you can use the -Ldirectory option to direct the linker to search directory
before 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_libs and then looking in /opt/fortran90/lib and /usr/lib.