38 Chapter 2
What Happens When You Compile and Link a Program
Looking “inside” a Compiler
Looking “inside” a Compiler
On the surface, it appears as though an HP-UX compiler generates an
a.out file by itself. Actually, an HP-UX compiler is adriver that calls
other commands to create the a.out file. The driver performs different
tasks (or phases) for different languages, but two phases are common to
all languages:
1. For each source file, the driver calls the language compiler to create
an object file. (See Also “What is an Object File?”.)
2. Then, the driver calls the HP-UX linker (ld) which builds an a.out
file from the object files. This is known as the link-edit phase of
compilation. (See Also “Compiler-Linker Interaction”.)
“Looking “inside” a Compiler” summarizes how a compiler driver works.
Figure 2-2 Looking “inside” a Compiler
The C, C++, FORTRAN, and Pascal compilers provide the-v (verbose)
option to display the phases a compiler is performing. Compilingmain.c
and func.c with the -v option produced this output on a Series 700
workstation (\ at the end of a line indicates the line is continued to the
next line):
$ cc -Aa -v main.c func.c -lm
cc: CCOPTS is not set.
main.c:
/opt/langtools/lbin/cpp.ansi main.c /var/tmp/ctmAAAa10102 \\
-D__hp9000s700 -D__hp9000s800 -D__hppa -D__hpux \\
-D__unix -D_PA_RISC1_1
cc: Entering Preprocessor.
/opt/ansic/lbin/ccom /var/tmp/ctmAAAa10102 main.o -O0 -Aa \\
func.c:
/opt/langtools/lbin/cpp.ansi func.c /var/tmp/ctmAAAa10102 \\
-D__hp9000s700 -D__hp9000s800 -D__hppa -D__hpux \\