HP-UX Linker and Libraries User's Guide
1 Compiling and Linking Programs on HP-UX
This chapter describes the process of compiling and linking a program.
DescriptionSection
Provides an overview of compiling on HP-UX.“Compiling Programs on HP-UX: An Example”
(page 16)
Describes how ld creates an executable file from one or more object.“Linking Programs on HP-UX” (page 21)
Describes conventions for using libraries with ld.“Linking with Libraries” (page 23)
Describes the process of loading and binding programs at run time.“Running the Program” (page 25)
Describes the thread-safe features.“Linker Thread-Safe Features” (page 26)
Compiling Programs on HP-UX: An Example
This chapter addresses the following:
• “Overview” (page 16)
• “Looking Inside a Compiler” (page 18)
• “Compiler-Linker Interaction” (page 19)
Overview
To create an executable program, you compile a source file containing a main program. For
example, to compile an ANSI C program named sumnum.c, shown below, use this command
(-Aa says to compile in ANSI mode):
$ cc -Aa sumnum.c
The compiler displays status, warning, and error messages to standard error output (stderr). If
no errors occur, the compiler creates an executable file named a.out in the current working
directory. If your PATH environment variable includes the current working directory, you can run
a.out as follows:
$ a.out
Enter a number: 4
Sum 1 to 4: 10
The process is essentially the same for all HP-UX compilers. For instance, to compile and run a
similar FORTRAN program named sumnum.f:
$ f90 sumnum.f
//Compile and link sumnum.f.
... //The compiler displays any messages here.
$ a.out
//Run the program.
...
//Output from the program is displayed here.
Program source can also be divided among separate files. For example, sumnum.c could be
divided into two files: main.c, containing the main program, and func.c, containing the function
sum_n. The command for compiling the two together is:
$ cc -Aa main.c func.c
main.c:
func.c:
16 Compiling and Linking Programs on HP-UX