Sample code for my online course "COBOL for the shits and giggles" on YouTube. The numbers at the beginning of each filename indicate which chapter of the course they belong to.
I use the GnuCOBOL compiler to test the examples in this course, set to the IBM COBOL dialect with the std=ibm flag. To compile a file, say example.cob, use the command
cobc -x -std=ibm example.cob
which will generate an executable example in the current directory.
Under the hood, GnuCOBOL is a transpiler that translates COBOL into C code, which is then compiled into binary. To create the intermediate C code instead of the binary, use the command
cobc -C -std=ibm example.cob
This should create three files, example.c (the program code), example.c.h (constants and auxiliary functions) and example.c.l.h ("local" variables from the Working Storage Section).
To compile and link multiple files, say a subprogram sub.cob and a main program main.cob into an executable execfile, use the command
cobc -x -std=ibm main.cob sub.cob -o execfile
Note that here you have to explicitely state the name of the produced executable with the -o flag.