HP Fortran Programmer Guide HP-UX 11i v1, HP-UX 11i v2, and HP-UX 11i v3 (B3908-90032,December 2012)

When you use the f90command to compile and link in the same command line, the driver passes
certain information—search paths, library names, and options—to the linker. If you use the ld
command to link separately, you must specify this same information on theld command line. Not
doing so can cause the link to fail. Using the samef90 command line to link as you use to compile
avoids the problem of passing insufficient or incorrect information to the linker.
To see what information f90passes to the linker, compile with the-voption (verbose mode). Here
is the hello.f90program (listed in “Compiling with the f90 command” on page 23) compiled
in verbose mode. The lines are numbered for the convenience of referencing:
1 $ f90 -v hello.f90
2 /opt/fortran90/lbin/f90com -cm -w90 -nbs -auto
-WB -hp\-Oq00,al,ag,cn,Lm,sz,Ic,vo,lc,mf,po,es,rs,sp,
in,vc,pi,fa,pe,Rr,Fl,pv,pa,nf,cp,lx,st,ap,Pg,
ug,lu,dp,fs,bp,wp\!\ hello.f90
3 hello.f90
4 program MAIN
5 external subroutine HELLO
6 7 Lines Compiled
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 f90command line.
Line 2 is the information f90passes 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 f90command line.
Lines 3 - 6 show the progress of the compilation; line 6 indicates that the compilation was successful.
Line 7 displays the value to which f90has defined the LPATHenvironment variable. If you use the
ld command to link hello.f90, you must defineLPATH on the command line before invoking the
linker. See “LPATH environment variable” on page 98.
Line 8 is the command line thatf90passes 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.f90successfully using
both the f90and ldcommands 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 setLPATH 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 f90options that you
can use to control the linker, see Table on page 14. To pass linker options from the f90command
line to the linker, use the-Wl option (for an example, see “Linking to shared libraries” on page
83). The HP Fortran Programmer’s Reference, fully describes the -Wloption.
Linking to libraries
When you use the f90command to create an executable program, the linker looks in the libraries
listed in Table 2-14 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 83.
Linking HP Fortran programs 49