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

Compiling and linking
Special-purpose compilations
Chapter 292
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 125). Like cpp directives, debugging lines enable the compiler to treat source
lines as either compilable statements or comments to be removed before compilation. But debugging lines
are nonstandard, available only in fixed-form source, and not nearly as powerful as the cpp directives.
Although cpp directives are not a standard feature of Fortran, cpp is a de facto standard feature of UNIX
systems.
This section discusses how to do the following:
Invoke cpp from the f90 command line.
•Use the -D option to define cpp macros.
Save the preprocessed output generated by cpp.
For more information about the cpp command and the directives it supports, see the cpp(1) man page.