Build tools: make and cobc flags
A minimal Makefile
A Makefile compiles every source to an object, then links them. GnuCOBOL objects end in .o. The main program is compiled with -x -c so its object carries the C main entry point; the called modules use plain -c:
payroll: main.o pay.o report.o
cobc -x -o payroll main.o pay.o report.o
main.o: main.cob
cobc -x -c -free -o main.o main.cob
%.o: %.cob
cobc -c -free -o $@ $<
The flags that matter
-c compiles without linking, -free enables free-format source, -x builds an executable, and -std=mf or -std=cobol2014 selects the standard dialect. -g adds source lines for the debugger:
cobc -c -free -std=cobol2014 -g -o pay.o pay.cob
Compile order
Compile copybook-free sources in dependency order: shared modules first, then programs that CALL them. cobc resolves calls at link time, so every called program must exist as an object before the final link.
The code on this page was run with GnuCOBOL 3.2.0 and GNU Make 4.4.1 on Alpine Linux 3.24.3 (x86_64) in a Docker container.
Article author: Arthur Isaev