Typical structure: main program calls subroutines via CALL "sub01" etc. Each in separate .cbl file.
cobc -x -o myprogram mainline.cbl sub01.cbl sub02.cbl sub03.cbl
Most people use this for small/medium programs with 3–10 source files.
cobc -c sub01.cbl
cobc -c sub02.cbl
cobc -c sub03.cbl
cobc -x -o myprogram mainline.cbl sub01.o sub02.o sub03.o
Or even more explicitly:
cobc -c sub01.cbl -o sub01.o
cobc -c sub02.cbl -o sub02.o
cobc -c sub03.cbl -o sub03.o
cobc -x mainline.cbl sub01.o sub02.o sub03.o -o myprogram
Useful for make / build systems, large projects.
cobc -x -o myprogram mainline.cbl
cobc -m sub01.cbl
cobc -m sub02.cbl
cobc -m sub03.cbl
This creates:
| Goal | Command (short form) | Produces | When to use |
|---|---|---|---|
| Single executable (recommended) | cobc -x -o prog *.cbl | One file: prog | Most normal cases |
| Separate compilation | cobc -c sub*.cbl + cobc -x main.cbl *.o -o prog | .o files + final executable | Make / build systems, large projects |
| Dynamic loading (modules) | cobc -x main.cbl + cobc -m sub*.cbl | Executable + .so/.dll files | Want to swap/update subroutines easily |
Most people use option 1 for small/medium programs. If your file names or PROGRAM-ID names differ, or you're using very old OpenCOBOL 1.1 behavior, let me know for adjusted commands.