Build tools: make and cobc flags
| A minimal Makefile | |
| The flags that matter | |
| Compile order |
A minimal Makefile
A Makefile compiles every source to an object, then links them. GnuCOBOL objects end in .o, and cobc -x links them into one executable:
payroll: main.o pay.o report.o
cobc -x -o payroll main.o pay.o report.o
%.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.
Next: Testing COBOL programs
Article author: Arthur Isaev