|Linking||Descriptions of cob Flags|
This chapter describes how to use the cob command. This command provides the interface to the Compiler and system linker. This interface enables you to handle all the phases involved in the production of an executable program.
The cob command enables you to handle all the phases involved in the production of an executable program by providing the interface between your COBOL source program and the following COBOL system components:
It also provides an interface to cc (the C compiler) and as (the assembler).
The cob command causes the named files to be processed with the aim of producing modules that can be linked or run.
There are three basic types of executable COBOL program; the cob command provides a straightforward means of creating a mixture of any of these types of program. The executable files types are:
Intermediate code files (.int files) and generated code files (.gnt files) are dynamically loadable, and do not have to be linked to be executed.
System executable files are files created from object code files by the Linker. System executable files can be:
The type of file output by cob depends on the type of file you input to it and the options you specify to the cob command. The file types recognized by cob are identified by their extensions as follows:
|.cbl or .CBL or .cob||COBOL source file|
|.int||COBOL intermediate code file|
|.gnt||Dynamically loadable generated code file|
|.s||Assembler source file|
|.c||C source file|
|.a||Archive of object module files|
|.so||Shared object module file|
|.o||Object module file|
cob assumes that any unrecognized options are either input files or valid linker options to be saved and used at link time. In this way, any archive files you supply to the cob command are passed to the linker, which pulls out only the referenced files from the archive.
You can use COBOL source files with extensions other than those listed above. To do so, you must specify the -k cob flag to identify them to cob (see the chapter Descriptions of cob Flags for details) or use the Cobextn facility (described later in this chapter).
To invoke the cob command, enter the following at the UNIX system prompt:
cob [options|file-name] ...
where the parameters are:
||Either one cob option or a group of cob options comprising one or more cob flags . See the section Specifying cob Options for details on the format of cob options.|
||The name of an input file. These files can be any
mixture of COBOL source code (.cbl, .CBL or .cob),
intermediate code (.int), linkable object code (.o or
.so), C source (.c), Assembler source (.s), or
archive (.a) files.
On some sytems, cob rejects any filenames that contain more than one period (.). If you try to specify multiple periods in a file-name, you receive the following error:
cob: "." is not a valid character in file-name stem
A cob option takes the form:
flag-intro flag-letter [parameter]
A group of cob options is equivalent to a separate option for each flag-letter with all options having the same intro. The parameter, if present, only apply to the last option. It takes the form:
flag-intro flag-letter[flag-letter]... [parameter]
where the parameters are:
||The hyphen (-) or the plus (+) character|
||A letter (or occasionally letters) selected from those listed in the section cob Flags later in this chapter, that flags the required option.|
||An optional string of characters that details exactly how the flagged option is to behave. The parameter cannot contain a space or tab character unless that character is contained in single (') or double (") quotation marks.|
There must be no spaces between flag-intro and flag-letter
or between two adjacent flag-letters but there can be one space
between the last flag-letter and the parameter if it is
present. (For example
-xve "" in which
represents a null parameter). The flag-intro must always be
preceded by a space character.
You can specify cob options in a number of ways, and the method used determines the order in which cob processes them. The cob command processes options from left to right for each method of specifying them. If an option appears more than once, cob uses the setting that it processed last for that option. At startup, the cob command searches for options in the following sequence of locations:
You might need to set options as a system or user default and then to unset them again in specific instances. By specifying a hyphen after the flag letter with no intervening space, you can unset the following options: -F, -c, -P and -U.
Options specified on the cob command line pass through the UNIX shell that carries out special processing on certain characters such as space, asterisk (*), parentheses (), single (') and double (") quotation marks before passing them to cob. If you need to pass these characters unchanged as part of an option, you must escape the shell processing. Under the UNIX shell this can be done by preceding the character with a backslash (\) or enclosing it in a pair of single or double quotation marks (see your UNIX system documentation for details of shell processing).
However, for your convenience cob enables you to use the syntax
in place of either "
mode(setting)" or mode\(setting\)
so enabling you to avoid these characters. The cob command converts
any syntax using the equals sign (=) into the form
To pass an actual equals sign (=) to the COBOL components, you must use
two equals signs together (==).
Note: The cob command treats the special characters single and double quotation marks in exactly the same way when used in an option, regardless of whether the option was specified on the command line or in one of the other locations. A parameter enclosed in a pair of quotation marks must not exceed 128 characters.
Assuming the following line in $COBDIR/cobopt:
-U -P -C "ans85 noalter warning=1"
specifying the cob command line:
cob -xU -C alter -C warning=2 prog.cbl
or the exact equivalent:
cob -xU -C "alter warning=2" prog.cbl
passes the COBOL source file
prog.cbl to the Compiler with
the final directive settings of ANS85 ALTER LIST(prog.lst)
WARNING(2). An executable program
prog is built, with any
unresolved symbols not being dynamically loaded at run time but flagged as
missing at link time.
System-wide default options are defined in the file $COBDIR/cobopt. This is the file the cob command reads when first invoked. Each line of this text file should correspond to one of the following formats:
[set environment-variable=value] [options] ... [cobextn: .ext [.ext] ... ]
where the parameters are:
||Any one of the environment variables supported by the COBOL System (see the appendix Micro Focus Environment Variables for details).|
||The value to which you want to set the specified environment variable.|
||Either one cob option or a group of cob options comprising one or more cob flags. See the start of section Specifying cob Options for details on the format of cob options.|
||A file-name extension that, in addition to the
standard ones of .cob, .cbl, or .CBL, denotes a
file that cob should treat as a COBOL source file. The extension must
begin with a period, and if more than one is specified on one line they
must be separated by a space or tab character. You can use more than one
If a line does not begin with one of the identifiers
cobextn:, it is taken as an options line.
Note: The contents of the file $COBDIR/cobopt affects the operation of COBOL for all users using the same $COBDIR; you should alter the file only after careful consideration of the implications.
Assuming the following two lines in $COBDIR/cobopt:
cobextn: .AD .FD -N "nobound" -C ans85
specifying the cob command line:
cob -u a.FD b.AD
passes the COBOL source files
to the syntax-check phase of the Compiler to be translated, under the
ANS85 directive, into intermediate code. The intermediate code is then
passed in turn to the Compiler's generate phase to be translated, under
the NOBOUND directive, into generated code.
User default options are defined using the COBOPT environment variable. COBOPT can either contain options that supplement or override the system default options defined in $COBDIR/cobopt, or it can specify the path of a file that contains such options. The options can extend over more than one line and each line must have the same format as described for the file $COBDIR/cobopt (see the section The $COBDIR/cobopt File).
The COBOPT environment variable can be set to a value that includes several lines by enclosing the entire value in single (') or double (") quotation marks that tells the UNIX shell to process each line as part of the one value. Under the Bourne shell, the Enter key can be typed to indicate the line-break. However, other types of shell might need a different way of showing the line-break. If you want to include a double quotation mark in the value, then remember to escape shell processing, for example by preceding it with a backslash (\) character.
See your UNIX system documentation for details of setting environment variables and shell processing.
You can include any valid cob command line in the COBOPT environment variable. If the line includes the -v cob flag, the whole line is echoed to the screen when it is passed to cob (see the chapter Descriptions of cob Flags for details on -v).
Specifying COBOPT as follows:
COBOPT="set COBCPY=/usr/lib/cblcpy:$COBDIR/srclib:$HOME/mylib:: -N nobound -C \"ans85 noalter list\" cobextn: .AD .FD" export COBOPT
causes cob to set the environment variable COBCPY for the duration of the cob command, it passes the directives ANS85 NOALTER LIST to the Compiler's syntax-check phase and passes the directive NOBOUND to the Compiler's generate phase. Note that $COBDIR and $HOME get expanded by the shell if the double quotation marks are used but not if single quotation marks are used.
Specifying COBOPT as follows:
COBOPT='-C "copyext=CPY,cpy nooptional-file" -N "nobound"'
causes cob to pass the directives COPYEXT(CPY,cpy) and NOOPTIONAL-FILE to the Compiler's syntax-check phase and the NOBOUND directive to the Compiler's generate phase.
Execution-time options (that is when cob executes, not when the application runs) are specified on the cob command line as described in the section Invoking the cob Command. Options given on the cob command line supplement or override any already specified in the $COBDIR/cobopt file or COBOPT environment variable.
You can specify on the command line any cob options listed in the section cob Flags later in this chapter and described in more detail in the chapter Descriptions of cob Flags.
Assuming neither $COBDIR/cobopt nor $COBOPT exist, specifying the following on the cob command line:
cob -xve "" -o my_rts -C xopen prog.cbl prog2.c
passes the XOPEN directive to the Compiler and instructs cob to compile
the COBOL source file
prog.cbl and the C source file
and to link the result into an executable file named my_rts that, when
run, expects the name of the program to run to be given on its own command
line. The cob utility also gives verbose notification of its progress.
See the section Command Line Examples later in this chapter for further examples.
While creating an executable module, the cob command passes each input program through a series of steps, each of which transforms the program from one file type into another file type. Thus, an output file from one step can serve as an input file for a subsequent step. These types are characterized by the file extensions as follows:
|Input File Extension
||Output File Extension
|Compile COBOL source code file into intermediate code file||.int|
|.int||Code generate for dynamic loading||.gnt|
|Code generate for static linking||.o|
|.s||Pass to system assembler||.o|
|.c||Pass C source text file to C Compiler||.o|
|Pass to system linker (ld)||No extension (also known as an a.out file)|
By default, cob processing ends when all COBOL source files have been compiled for animation; that is, a dynamically loadable intermediate code file (with extension .int) and an Animator file (with extension .idy) have been created. Other end points can be specified by using cob options (see the section cob Flags later in this chapter).
If any of the input files are beyond the desired end point, cob statically links them with the dynamic loader. This produces an executable run time system, that can be used to load and run any dynamically loadable files.
Any temporary files produced at any of the intermediate stages of processing are removed once used, with the exception of any .int and .o files, that are left in the same directory as their input file.
A dynamically linked, statically linked or dynamically loadable COBOL program, can access (using the COBOL CALL verb) any other statically linked module in the same statically linked COBOL module or any other dynamically loadable module. Assembler, C, or any other language modules must conform to the C calling conventions and must be statically linked into the COBOL executable. For details on creating these types of modules, see the chapter Linking.
Note: On file systems that support long filenames, you are recommended to keep the length of program source filenames below the entry point name limit. See the chapter Linking for further details.
To access COBOL system components, the cob command must know where they are located. They must all be located in a directory in which a COBOL system has been installed and the directory is represented in this chapter as $COBDIR. The cob command assumes a default $COBDIR directory of /opt/lib/cobol on UNIX System V Release 4, or /usr/lib/cobol otherwise. If your COBOL system has been installed here then you do not need to specify the COBDIR environment variable. If you put the Micro Focus COBOL system software elsewhere, then you must set the COBDIR environment variable to tell cob in which directory to search for the system components. You can choose to install different versions of the COBOL system on your machine, in which case you select which one to use by simply setting its location in COBDIR. For example:
COBDIR=/usr/cob41u1 export COBDIR
specifies that the system components are located in the directory /usr/cob41u1. If the cob command is not on the UNIX search path then you must change the value of PATH. For example:
PATH=$PATH:/usr/mfcobol/utils export PATH
/usr/mfcobol/utils is the directory where you
installed the driver utilities.
On platforms that support dynamic linking, you should ensure that LD_LIBRARY_PATH (on UNIX SVR4-based systems), LIBPATH (on AIX), or SHLIB_PATH (on HP/UX systems) is set to $COBDIR/coblib.
By default, files output by the cob command are put in the current directory. By default, any temporary files created are put in the system temporary directory; however, you can put them elsewhere by setting the TMPDIR environment variable and specifying a valid path-name. See the appendix Micro Focus Environment Variables for details on using TMPDIR.
The following flags can be used with the cob command to specify any action the system components should take while creating an executable module and to determine the type of file output. For full details on the effect of these flags, see the chapter Descriptions of cob Flags.
|-A as_option||Pass as_option to assembler (as)|
|-a||Compile for animation. This is the default|
|-B mode[=lib]||Select the system linker binding mode|
|+B mode[=lib]||Select the system linker binding mode and pass to system linker after COBOL libraries|
|-b format||Specify the object module format of any object produced (SCO Open Desktop 5 only).|
|-C directive||Pass syntax-check phase directive to the Compiler|
|-CC cc_option||Pass cc_option to C compiler (cc)|
|-c||Compile no further than statically linkable object module (.o)|
|-d symb||Dynamically load symb|
|-e epsym||Set initial entry point|
|-F||Create an RTS quickly|
|+F symb||Create an RTS quickly and add symb to a linked data table. (Not available on Linux)|
|-f||Reserved for future use by Micro Focus|
|-G||Generate for animation|
|-g||Create information for symbolic debugger|
|-I symb||Include symb in executable file|
|-i||Compile to .int code for unlinked environment|
|-k cobol-file||Recognize COBOL source file with non-standard file-name extension|
|-L dir||Pass option to system linker, changing search algorithm and maintaining relative ordering|
|+L dir||Pass option to system linker after all other options, changing search algorithm|
|-l lib||Pass option to system linker, maintaining relative ordering|
|+l lib||Pass option to system linker after all other options|
|-m symb=newsym||Map text symb onto newsym|
|-N directive||Pass generate phase directive to the Compiler|
|-o file-name||Specify output file-name|
|-P||Produce COBOL compilation listing file|
Pass flag to C compiler to use profiling routines. (Not available on Linux)
|-Q ld_option or
-Q,1 ld_option or
|Pass ld_option to system linker (ld)|
|-q||Reserved for future use by Micro Focus|
|-U||Dynamically load unresolved symbols. (Not available on Linux)|
|-u||Compile to .gnt code for unlinked environment.|
|-V||Report version number|
|-v||Set verbose mode|
|-W err-level||Control error level for cob termination|
|-X symb||Exclude text symb from the executable output file|
|-x||Process to statically or dynamically linked executable module|
|-z||Reserved for future use by Micro Focus|
Any options that are not recognized are passed to the system linker (ld). However, you are encouraged to use the -Q flag to explicitly pass options to the linker. Any linker flags that take parameters must be passed using the -Q flag.
cob flags -c, -F, -P and -U are binary global options (that is, they select features that can potentially affect several of the input files). Any of these options can be turned off once selected by appending a hyphen (-) to the option letter. This enables any global binary options selected in the system $COBDIR/cobopt file to be overridden.
These examples show several uses of the cob command to compile, code generate and link programs.
As this is the default case, the -a flag does not need to be specified.
cob -x pi.cbl
On systems that support dynamic linking, you also need to specify -B static to produce a static linked executable. Otherwise, a dynamically linked executable is produced by default. See the chapter Linking.
cob -i pi.cbl
This differs from the default case, shown in the first example, because an end-point has been specified. In this case pi.int is not suitable for animation.
cob -u pi.cbl
cob -x -e "" pi.cbl
Specifying the -e flag with a null parameter (that is, "") ensures that the entry point is read from the command line at run time. In effect, pi is linked to a full RTS as a callable subprogram, so to invoke pi you would use the command:
cob -xo newrts
cob -o newrts routines.c
cob -xI COBWIN2 -o newrts
See your Programmer's Guide to User Interfaces for full details on windowing syntax.
For details on how to execute the files produced using the cob command, see the chapter Running. See also the chapters Compiling, Generating and Linking for additional details.
The cob command is used to interface to the COBOL compilation system. Compiler directives can be specified in a variety of ways, including via cob and via the program source files. The following sections describe all the ways that compiler directives can be specified.
The Micro Focus COBOL Compiler accepts source from a standard UNIX text file (as created by a UNIX editor such as vi). The format of this is the same as for standard COBOL, described in your Language Reference.
Each line of your COBOL source programs, including the last line, must be terminated by a new line character.
Your COBOL source programs must not contain any control characters (characters with hexadecimal values x"00" to x"1F" inclusive, or x"7F") except the tab character, unless they are embedded in literal strings. Tab is expanded with spaces to the next character position that is a multiple of eight.
You can specify compiler directives in a number of ways, and the method used determines the order in which the compiler processes them. The Compiler processes directives from left to right for each method of specifying them. If a directive appears more than once, the Compiler uses the setting that it processed last for that directive. The compiler searches for directives in the following sequence of locations:
These methods are listed in the order in which the compiler processes directives for each COBOL source file. This order of precedence means that a directive set on the command line would override another setting for that directive set in cobol.dir. For example, specifying the NOANS85 Compiler directive on the command line overrides ANS85 in cobol.dir.
You can further customize the Compiler's behavior by creating your own directives file; that is, an ASCII text file in which is defined an entire set of directives to be passed to the Compiler at one time. You can use either the DIRECTIVES or USE directive to pass this user directives file to the Compiler. You can determine the precedence for processing your directives file by specifying the DIRECTIVES or USE directive by any of the methods described above. See the section The DIRECTIVES and USE Directives later in the chapter.
Parameters to directives given in a $SET statement are converted to upper case; parameters to directives given on the cob command line or in a directives file retain their case.
The methods of specifying cob options and of specifying compiler directives in cob options are given earlier in the section Invoking the cob Command. The additional methods of specifying Compiler directives are described in the following sections.
cobol.dir is a directives file that is processed automatically by the Compiler, as if the directive:
were encountered by the compiler as the very first directive after startup. Consequently, Compiler directives contained in cobol.dir override the defaults built into the Compiler but can be overridden in turn by directives specified in the ways listed above. Generate phase directives cannot be specified in the cobol.dir directives file.
The Compiler looks for a cobol.dir file first in the current directory. If it finds one there, it uses it. Otherwise, it looks in the COBOL system directory $COBDIR.
If the Compiler rejects a directive contained in the cobol.dir file, compilation continues. However, if the Compiler rejects directives from either the command line or a directives file specified on the command line, compilation terminates. Therefore, if you create or change a cobol.dir file, you should do a trial compilation and watch for "rejected" messages at the beginning when the directives are being processed. If any occur, correct the cobol.dir file and retry until no errors are reported.
Many Compiler directives can be specified in the program source code in $ SET statements. Compiler directives specified in this way supplement or override options specified in $COBDIR/cobopt or in COBOPT. Generate phase directives cannot be specified using $SET statements.
You specify the $SET statement in the following format with the $ character in column 7:
$SET directive["parameter"] ...
where the parameters are:
||One of the Compiler directives described in the chapter Directives for Compiler whose phase is identified as "syntax check". It cannot be a generate phase directive (that is, one whose phase is identified as "generate").|
||A qualifier to
You cannot precede a parameter with an equals sign (=) in a $SET
||Indicates that further Compiler directives can be specified following the same format.|
The $ character must be in column 7; if it is not, the Compiler does not recognize it and can produce spurious errors. The same is true for any character at the start of a source file that the Compiler does not recognize. Additionally, the $SET statement must not be terminated with a period (.).
If more than one directive is specified they must be separated by spaces. A $SET statement cannot be continued onto a new line, but it can be followed by additional $SET statements.
You can specify any number of $SET statements in your source code, and these can appear anywhere in the code. If you want to specify a dialect-controlling Compiler option, for example ANS85, this must be an "initial" $SET statement; that is, one that is not preceded in the source file by any source statements except other $SET statements. Once you have set a dialect-controlling option at the beginning of your source code, you cannot unset it later in the program. When a directive is specified on a $SET other than an initial $SET, it affects compilation from the point the $SET is encountered onwards.
The chapter Directives for Compiler indicates that Compiler directives are allowed on $SET statements, distinguishing those only allowed on initial $SET statements.
Both of the following examples have the same effect; they cause the Compiler to assume all file assignments to data names are resolved externally and to flag features in your program that are not in the ANSI'85 dialect of the COBOL language:
$SET assign(external) flag(ans85)
$SET assign "external" flag"ans85"
The DIRECTIVES and USE Compiler directives enable you to pass to the Compiler a user file containing a predefined set of directives. You can specify the DIRECTIVES or USE directive on the command line, in a $SET statement, in the cobol.dir file or in the $COBDIR/cobopt file. Generate phase directives cannot be specified using DIRECTIVES or USE directives. The format for these directives is:
file-name is the name of the user file
containing the set of directives you want to pass to the Compiler. It can
be any valid file-name except cobol.dir or
A directives file is a standard ASCII text file containing any number of lines. Each line can contain one or more directives or comments. Directives in the directives file must be separated by a space and cannot be broken across two lines. Comment lines are indicated by an ampersand character (&) in column 1.
The Compiler reads the directives from the file until the end of file (EOF) is reached or another DIRECTIVES or USE Compiler directive is encountered.
If you specify the DIRECTIVES directive in another directives file, the Compiler switches to the new directives file for processing and then returns to the original directives file. When the Compiler completes processing the directives file, it then processes subsequent directives on the command line or in $SET statements.
Directives in a directives file are processed as if they were coded in place of the DIRECTIVES directive. Consequently, restrictions applying to any directive at that time also apply to all the directives in a directives file read at that time. See also 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.
|Linking||Descriptions of cob Flags|