1 Compiling and Linking Programs on HP-UX
This chapter describes the process of compiling and linking a program.
Section | Description |
|
|
Provides an overview of compiling on | |
| |
|
|
Describes how ld creates an executable file from one or more object. | |
|
|
Describes conventions for using libraries with ld. | |
|
|
Describes the process of loading and binding programs at run time. | |
|
|
Describes the | |
|
|
Compiling Programs on
This chapter addresses the following:
•“Looking Inside a Compiler” (page 18)
•
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
$ cc
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
$ 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
func.c:
16 Compiling and Linking Programs on