HP Fortran Programmer's Guide (September 2007)

Compiling and linking
Special-purpose compilations
Chapter 2 89
Example 2-6 hi.f90
SUBROUTINE say_hi()
PRINT *, 'Hi!'
END SUBROUTINE say_hi
Example 2-7 bye.f90
SUBROUTINE say_bye()
PRINT *, 'Bye!'
END SUBROUTINE say_bye
Example 2-8 greet.f90
PROGRAM main
CALL say_hi()
CALL say_bye()
END PROGRAM main
The following command line creates the PIC object files (the -c option suppresses linking):
$ f90 -c +pic=short bye.f90 hi.f90
The next command line links the object files into the shared library:
$ ld -b -o my_lib.sl bye.o hi.o
The last command line compiles the source file greet.f90 and links the object code with the
shared library to produce the executable program a.out:
$ f90 greet.f90 my_lib.sl
The following is the output from a sample run of the executable program:
$ a.out
Hi!
Bye!
Using the C preprocessor
You can use the f90 command to pass source files to the C preprocessor (cpp) before they are
compiled. If the source files contain C preprocessor directives, cpp will act on the directives,
modifying the source text accordingly. The f90 driver will then pass the preprocessed source
text to the compiler. Adding cpp directives to program source files and having the cpp
command preprocess them is a convenient way to maintain multiple versions of a
program—for example, a debugging version and a production version—in one set of files.
cpp directives are similar to debugging lines, a feature of many Fortran implementations (see
“Using debugging lines” on page 124). Like cpp directives, debugging lines enable the
compiler to treat source lines as either compilable statements or comments to be removed