Installation [1]Edit

  1. Download the nightly Windows binaries: https://sourceforge.net/projects/gnucobol/files/gnucobol/nightly_snapshots/
  2. Unzip the distribution file into c:\gnuCOBOL and my examples will assume that location.
  3. In c:\gnuCOBOL\bin you will find various EXE files particularly cobc.exe and cobcrun.exe
  4. In System Properties | Environment Variable you need to add the path c:\gnucobol\bin

Open a command prompt and check

C:\>cobc -V
cobc (GnuCOBOL) 3.1-dev.0
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Keisuke Nishida, Roger While, Ron Norman, Simon Sobisch, Edward Hart
Built May 05 2020 16:26:39
Packaged May 05 2020 15:48:49 UTC
C version (MinGW) "5.3.0"

C:\>

WorkflowEdit

There are parameters you’ve got to pass to the compiler every time. It is easiest just to have a bat file. I’ll call mine COBOL.BAT and simply put it into c:\gnucobol\bin

C:\gnuCOBOL\bin>type cobol.bat
@echo off

rem Compile a COBOL program

rem are env strings already defined? (tried using () here, but it failed so goto it is

if NOT "%COB_MAIN_DIR%" == "" goto cont

rem define env strings

set COB_MAIN_DIR=c:\gnucobol\
set COB_CONFIG_DIR=%COB_MAIN_DIR%config
set COB_COPY_DIR=%COB_MAIN_DIR%copy
set COB_CFLAGS=-I"%COB_MAIN_DIR%include" %COB_CFLAGS%
set COB_LDFLAGS=-L"%COB_MAIN_DIR%lib" %COB_LDFLAGS%
set COB_LIBRARY_PATH=%COB_MAIN_DIR%extras
set PATH=%COB_MAIN_DIR%bin;%PATH%
	
:cont

rem Start the compiler

cobc -x %*

-x indicates the output from the compiler should be an EXE file.

If you want to use the cobc command directly, simply use “cobol -V” once to set up the environment, then cobc can be used directly.

TestingEdit

If you want to do a hello world test, here is the code:

C:\gnuCOBOL>type hellow.cob
        id division.
        program-id. hellow.
        procedure division.
            display 'hello world!'.

Note there are 8 leading spaces on every line and another 4 for the DISPLAY verb. This is how fixed format COBOL code must be written.

Execute the program hellow.exe in the terminal.

ReferencesEdit