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

Compiling and linking
Linking HP Fortran programs
Chapter 278
Linking HP Fortran programs
This section discusses how to link object files and covers the following topics:
The advantages of using the f90 command for linking as well as for compiling
How to link libraries, including shared libraries
How to establish the search rules used by the linker when it looks for libraries
For more information about the linker, refer to Programming on HP-UX and to the ld(1) man page.
Linking with f90 vs. ld
By default, the f90 command both compiles and links, producing an executable program. You can modify
this behavior with the -c option, which causes f90 to compile only, writing the object files (if the
compilation is successful) in the current working directory. If the command line contains object files only,
f90 passes them to the linker (ld) for linking into the executable program. In other words, you can use the
f90 command to compile and link in one command line or in separate command lines. You do not need to
invoke the ld command separately.
In fact, we recommend that you use the f90 command whenever you link HP Fortran object files and that
you use the same command line for linking as for compiling.
When you use the f90 command 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 the ld command line. Not doing so can cause the link
to fail. Using the same f90 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 f90 passes to the linker, compile with the -v option (verbose mode). Here is the
hello.f90 program (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: