Monday, May 29, 2017

COBOL on Windows

For better or worse, I decided to learn COBOL. After a bit of research, I came across GNU Cobol, which had been Open COBOL in a future life. I wanted this to work in Windows and that's where the trouble began.

The easiest route was to run GNU Cobol in the Linux Layer for Windows, otherwise known as Bash for Windows 10. In Bash, it was simple enough to "sudo apt-get install open-cobol", which installs GNU Cobol 1.1, gcc, and everything else needed to build COBOL programs. Of course, this solution produced Linux binaries.

Getting GNU Cobol producing Win32/64 binaries was quite a bit more tedious. GNU doesn't distribute binaries, so it's up to one to build it yourself or find someone who has built it already. In the end I used the binary distribution from kiska.net for x64. However, GNU Cobol only generates C++ code and executes GCC to build the executable. The distribution from kiska didn't include the GCC, so I installed MinGW and the GCC from there.

Next, I had to configure the following environment variables for the COBOL compiler:
COB_CONFIG_DIR=c:\Program Files\OpenCOBOL\config
COB_COPY_DIR=c:\Program Files\OpenCOBOL\copy
COB_LIBRARY_PATH=C:\Program Files\OpenCOBOL\lib
COB_SCREEN_ESC=Y
COB_SCREEN_EXCEPTIONS=Y

The location of the MinGW bin directory and the GNU Cobol bin directory have to be added to the PATH.

Finally, the COBOL headers and libraries had to be added to MinGW where the GCC could find them. This included libcob.h, gmp.h, libcob, libpdcurses*, libgmp*, libdb*, libcob* from the lib and include directories.

With all that done, I am now able to produce 64-bit binaries for Windows.