|Packaging Applications||Using the Compiler|
This chapter introduces you to compiling programs. For details on compiling, see the chapter Using the Compiler.
As you saw in the section Executable File Types in the chapter Packaging Applications, you can create three types of executable files:
To create an executable file you need to compile your program using the Compiler. If you want to create a system executable file, you will subsequently need to link the compiled file. Note that compiling and linking can be done in one step using cob.
The Compiler compiles a program in two phases:
If you compile a program to object code, you must subsequently link the file using cob.
To compile, you use the cob command. The sections below give you general information on compiling programs using the cob command. For detailed information on using cob, see the chapter COBOL System Interface (cob).
You can create an intermediate code file using the Compiler directly. There is no need to link the program. However, you will need to run the program using the cobrun program, or create a system executable file that calls the program. For more details see the chapter Packaging Applications.
You can compile the source code file myprog.cbl to intermediate code as follows:
cob -i myprog.cbl
This creates an intermediate code file called myprog.int.
cob -a myprog.cbl
also creates an intermediate code file, along with files for use by Animator.
You create a generated code file using the Compiler. There is no need to link the program. However, to run the program you need to do one of the following:
For example, you can compile the source code file myprog.cbl to generated code as follows:
cob -u myprog.cbl
This creates a generated code file called myprog.gnt.
You can also create a .gnt file from an .int file using:
cob -u myprog.int
Creating a system executable file involves two steps:
Both steps are done using the cob command.
For example, if the file myprog.cbl contains the source program, you can compile the program to a system executable file in one step, as follows:
cob -x myprog.cbl
This creates a system executable file called myprog.
Many options are available for controlling the way your program is compiled. These options are specified using directives when you invoke the Compiler. You can enter Compiler directives individually on the command line, or you can create default directives which are then invoked as a group either automatically, or from the command line, or from within the source code.
For normal operation you need to know about and use very few directives. In the majority of cases you will use the default values. If you do need to use other directives they are described in detail in the chapter Directives for Compiler.
Many directives direct the Compiler to create code which is compatible with other COBOL compilers. More details of these can be found in your Compatibility Guide. The directives you are most likely to use are those that define the output produced by the Compiler.
For more information about setting directives, see the section Directives in the chapter Using the Compiler.
This section shows you the best way to use the Compiler to keep your compilation time down.
If you are creating a large application, you can cut down the amount of time taken to compile a program by compiling using .int files. If you compile using the intermediate code file instead of the source file the Compiler will omit the check phase and go straight to the generate phase. For example, to compile myprog.int to a .gnt file you would need to type:
cob -u myprog.int
This would create the generated code file myprog.gnt.
To create a system executable file from an .int file you would type:
cob -x myprog.int
Compiling to generated code takes longer than compiling to intermediate code. You only need to create generated code when your program is free of bugs and ready for production.
There are several Compiler directives that affect the speed of a compilation. They are:
These directives are described briefly below. For more information on all directives, see the chapter Directives for Compiler.
|ALTER||The ALTER directive enables the use of ALTER statements in your program. If you know there are no ALTER statements in your source code, specifying NOALTER enables the Compiler to produce slightly more efficient code and produce it more quickly. The Compiler assumes ALTER as the default.|
|COPYLIST||COPYLIST tells the Compiler to list the contents of all copyfiles and include files. If you are creating a listing file, specifying NOCOPYLIST results in faster compilation time, as COBOL copyfiles are not expanded in the listing. The Compiler assumes COPYLIST as the default.|
|LIST||LIST specifies that you want a listing file to be created. If you do not need to create a listing file, specifying NOLIST (the default) speeds up the compilation process.|
QUAL is only required if you are using
qualified data-names; for example:
elementary-item-a of group-item-1
The Compiler assumes QUAL as the default.
|QUALPROC||If your program uses qualified data-names, but not qualified paragraph-names, compilation can be accelerated by specifying NOQUALPROC. The Compiler assumes QUALPROC as the default.|
|SEG||The SEG directive enables the use of segments in your program. If you know there are no segments in your source code, specifying NO enables the Compiler to produce slightly more efficient code and produce it more quickly. The Compiler assumes SEG as the default.|
If you will always compile a program with a particular directive set you could use the $SET command in your program code to set the directive. For example, if your program does not use ALTER statements, you could set the directive in your program:
See the section Directives in the chapter Using the Compiler for more information on setting directives.
For more information on compiling and linking programs, see the following chapters in this manual :
For information on Compiler directives, see the chapter Directives for Compiler.
Copyright © 1999 MERANT International Limited. All rights reserved.
This document and the proprietary marks and names used herein are protected by international law.
|Packaging Applications||Using the Compiler|