This guide provides the necessary steps to install, configure, and run COBOL programs on a Windows environment using the GnuCOBOL compiler.
You can download the GnuCOBOL compiler from either of these sources:
.7z to .exe before running the installer.Extract or install the contents to a path without spaces, for example: C:\GnuCOBOL.
To ensure the compiler can find its configuration files and binary tools, set the following variables in your System Environment Variables.
| Variable Name | Value |
|---|---|
COB_MAIN_DIR | C:\GnuCOBOL |
COB_CONFIG_DIR | C:\GnuCOBOL\config |
COB_COPY_DIR | C:\GnuCOBOL\copy |
COB_INCLUDE_DIR | C:\GnuCOBOL\include |
COB_LIB_DIR | C:\GnuCOBOL\lib |
Add the following to your Path variable:
C:\GnuCOBOL\binTo get syntax highlighting and code completion in VSCode, install the following extensions:
To compile a COBOL program, use the cobc command in your terminal:
cobc -x -free hello.cob -o hello.exe
-x: Build an executable program.-free: Use free-format COBOL (if applicable).-o: Specify the output file name.Run the compiled executable:
./hello.exe
You're all set! You can now write, compile, and execute COBOL programs on your Windows machine.