HP Fortran Programmer's Guide (September 2007)

Compiling and linking
Linking HP Fortran programs
Chapter 2 77
7 LPATH is: /opt/fortran90/lib/pa1.1:/usr/lib/pa1.1:
/opt/fortran90/lib:/usr/lib:/opt/langtools/lib
8 /usr/ccs/bin/ld -x /opt/langtools/lib/crt0.o hello.o
/opt/fortran90/lib/libF90.a -lcl -lc -lisamstub
Line 1 is the f90 command line.
Line 2 is the information f90 passes to the compiler, including the full pathname of the
compiler, the name of the source file (hello.f90), and the internal names of the option
settings as determined by the defaults and the f90 command line.
Lines3-6show the progress of the compilation; line 6 indicates that the compilation was
successful.
Line 7 displays the value to which f90 has defined the LPATH environment variable. If you
use the ld command to link hello.f90, you must define LPATH on the command line
before invoking the linker. See “LPATH environment variable” on page 95.
Line 8 is the command line that f90 passes to the linker (ld). If you use the ld command
to link hello.f90, the command line should be similar to the one shown here.
As noted in the comments on lines 7 and 8, compiling and linking hello.f90 successfully
using both the f90 and ld commands requires three command lines:
$ f90 -c hello.f90 # compile
$ export LPATH=/opt/fortran90/lib/pa1.1:/usr/lib/pa1.1:\
/opt/fortran90/lib:/usr/lib:/opt/langtools/lib # set LPATH
$ ld -x /opt/langtools/lib/crt0.o hello.o \
/opt/fortran90/lib/libF90.a -lcl -lc -lisamstub # link
The command line to set LPATH in the csh is:
$ setenv LPATH /opt/fortran90/lib/pa1.1:/usr/lib/pa1.1:\
/opt/fortran90/lib:/usr/lib:/opt/langtools/lib # set LPATH
For more information about the linker, see the ld(1) man page. For a list of f90 options that
you can use to control the linker, see Table on page 14. To pass linker options from the f90
command line to the linker, use the -Wl option (for an example, see “Linking to shared
libraries” on page 80). The HP Fortran Programmer’s Reference, fully describes the -Wl
option.
Linking to libraries
When you use the f90 command to create an executable program, the linker looks in the
libraries listed in Table 2-13 to resolve references. By default, the linker uses the shared
libraries, if available. For information about shared libraries, see “Linking to shared libraries”
on page 80.