Quality, Reliability & Service
Thank You For Visiting
Brooks Computing Systems - Jacksonville
Visit https://bcs.archman.us
GnuCOBOL – Compiling Main Program + Subroutines

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
  • -x = produce executable program
  • -o myprogram = name of the final executable
  • List main program first, then all subroutines
  • Result: single executable file myprogram (or myprogram.exe on Windows)

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:
  • myprogram (executable)
  • sub01.so / sub01.dll, sub02.so, sub03.so (dynamic libraries)
Run with: ./myprogram (Linux/macOS) or myprogram.exe (Windows).
GnuCOBOL will automatically load the modules when CALL "sub01" is executed (provided the .so/.dll files are in the current directory or in COB_LIBRARY_PATH).

GoalCommand (short form)ProducesWhen to use
Single executable (recommended)cobc -x -o prog *.cblOne file: progMost normal cases
Separate compilationcobc -c sub*.cbl + cobc -x main.cbl *.o -o prog.o files + final executableMake / build systems, large projects
Dynamic loading (modules)cobc -x main.cbl + cobc -m sub*.cblExecutable + .so/.dll filesWant 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.