Compaq COBOL AAQ2G1FTK User Manual

Page 49

Advertising
background image

Developing Compaq COBOL Programs

1.2 Developing Programs on Tru64 UNIX

Any messages issued during the compilation are inserted in the listing file. A
listing file is useful for debugging the source code. Use the

-V

or

-list

flag to

produce a listing; you may also use

-cross_reference

,

-copy_list

,

-flagger

,

-machine_code

,

-map

, and/or

-warn

, all of which affect the contents of the listing

file.

Diagnostic messages provide information for you to determine the cause of an
error and correct it. If the compiler creates a listing file, it writes the messages to
the listing file.

1.2.3 Linking a Compaq COBOL Program on Tru64 UNIX

Once your program has compiled successfully, the system passes the resulting
object file (which has the suffix .o by default) to the linker to create an executable
image file. By default, the executable image file has the name a.out. (To change
this default, specify

-o

filename on the

cobol

command line.) This file can be run

on the Tru64 UNIX system.

The

ld

linker provides the following primary functions:

Generates appropriate information in the executable image for virtual
memory allocation

Resolves symbolic references among object files being linked, including
whether to search in archive or shared object libraries

Assigns values to relocatable global symbols

Performs relocation

The linker produces an executable program image with a default name of a.out.

When you enter a

cobol

command, the

ld

linker is invoked automatically unless

a compilation error occurs or you specify the

-c

flag on the command line.

1.2.3.1 Specifying Object Libraries for Linking

You can specify object libraries on the

COBOL

command line by using certain

flags or by providing the file name of the library. These object libraries are also
searched by

ld

for unresolved external references.

When

cobol

specifies certain libraries to

ld

, it provides a standard list of COBOL

library file names to

ld

. The

ld

linker tries to locate each of these library file

names in a standard list of library directories. That is,

ld

attempts to locate each

object library file name first in one directory, then in the second, and then in the
third directory on its search list of directories.

To display a list of the compilers invoked, files processed, and libraries accessed
during linking, specify the

-v

flag.

In addition to an object file created by the compiler, any linker flags and object
files specified on the

cobol

command are also passed to the

ld

linker. The

linker loads object files according to the order in which they are specified on the
command line. Because of this, you must specify object libraries after all source
and object files on the

cobol

command line.

To help identify undefined references to routines or other symbols in an object
module, consider using the

nm

command. For instance, in the following example

the

nm

command filtered by the

grep

command lists all undefined (U) symbols:

% cobol -c ex.cob
% nm -o ex.o | grep U

Developing Compaq COBOL Programs 1–19

Advertising