Compiling from the command line

To compile a COBOL program from the command line, issue the cob2, cob2_j, or cob2_r command, depending on the type of the program. Each of these commands also invokes the linker.

Read syntax diagramSkip visual syntax diagram
cob2 command syntax

>>-+-cob2---+--+---------+--filenames--------------------------><
   +-cob2_j-+  '-options-'              
   '-cob2_r-'                           

Choose the command as follows:

When you compile using cob2_j or cob2_r, the THREAD compiler option is automatically included as a default invocation option.

To compile multiple files, specify the file-names at any position in the command line, using spaces to separate options and file-names. For example, the following two commands are equivalent:

cob2 -g -qlib filea.cbl fileb.cbl -q"flag(w)"
cob2 filea.cbl -g -q"flag(w)" fileb.cbl -qlib

Each of the three cob2* commands accepts compiler and linker options in any order on the command line. Any options that you specify apply to all files on the command line.

Only source files that have suffix .cbl or .cob are passed to the compiler. All other files are passed to the linker.

The default location for compiler input and output is the current directory.

Examples: using cob2 for compiling