Run COBOL in windows
Why COBOL in 2022?
The reason is, many migration still happening from mainframe COBOL to Java or .NET
If the developer knows how test the COBOL in his local machine, then it benefits the migration to speed up
This article demonstrates the Cygwin dependencies to compile gnuCOBOL from source code
Install Cygwin with below list of dependencies
- gettext
- gettext-devel
- gcc
- g++
- fcntl
- gmp
- gmp-devel
- mpfr-devel
- mpfr
- db
- db-devel
- libncurses
- libncurses-devel
- zlib
- zlib-devel
- lzma
- lzma-devel
- libiconv-devel
- python38
- python38-devel
modify "Makefile"
PREFIX ?= /usr
run make and make install
$ make
$ make install
mkdir -p /usr/lib /usr/include/cjson
cp -a cJSON.h /usr/include/cjson
cp -a libcjson.so libcjson.so.1 libcjson.so.1.7.13 /usr/lib
cp -a cJSON_Utils.h /usr/include/cjson
cp -a libcjson_utils.so libcjson_utils.so.1 libcjson_utils.so.1.7.13 /usr/lib
Run the below commands
$ ./configure --prefix=/usr
config.status: executing libtool commands
Done configuring
$ make CFLAGS='-I/usr/include/python3.8' CXXFLAGS='-I/usr/include/python3.8'
$ make install
make[1]: Leaving directory
Download gnuCOBOL
Unzip and run below commands
$ ./configure --prefix=/usr
configure: Use gettext for international messages: yes
configure: Use fcntl for file locking: yes
configure: Use math multiple precision library: gmp
configure: Use curses library for screen I/O: ncursesw
configure: Use Berkeley DB for ISAM I/O: yes
configure: Use libxml2 for XML I/O: yes
configure: Use cJSON for JSON I/O: no
$ make
$ make install
If you are using MSYS2 then the gnucobol already available for install with pacman
Check gnuCOBOL Version
$ cobc --version
cobc (GnuCOBOL) 3.1-rc1.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 Aug 23 2020 17:36:16
Packaged Jul 01 2020 00:39:30 UTC
C version "9.3.0"
Example COBOL code "test.cob"
IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO-WORLD.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-OUT PIC X(80) VALUE SPACES.
01 WS-N PIC 9(2) VALUE 0.
01 WS-CENTER PIC 9(2) VALUE 20.
PROCEDURE DIVISION.
PERFORM VARYING WS-N FROM 1 BY 2 UNTIL WS-N > 26
MOVE ALL '*' TO WS-OUT(WS-CENTER:WS-N)
COMPUTE WS-CENTER = WS-CENTER - 1
DISPLAY WS-OUT
END-PERFORM.
STOP RUN.
Compile COBOL
$ cobc -x test.cob
test.cob:19: warning: line not terminated by a newline
Run the EXE
$ ./test
*
***
*****
*******
*********
***********
*************
***************
*****************
*******************
*********************
***********************
*************************
Finished!
Happy COBOL Coding :)