GNU COBOL Setup Secrets

Find Tips and tricks on how to better use the Zeus editor. Feel free to post your own tips but please do not post bug reports, feature requests or questions here.
jussij
Site Admin
Posts: 2445
Joined: Fri Aug 13, 2004 5:10 pm

GNU COBOL Setup Secrets

Postby jussij » Tue Jan 03, 2017 3:06 am

Trying to get GNU COBOL to work on Windows appears to be a bit of a black art :(

Some time ago these setup instructions where written and obviously at that time they worked since they produced an executable and that executable ran.

I took those earlier instructions and did an update as described below.

1. Updating the Compiler Binary
On revisiting those instructions I realised the link to the compiler in that setup is outdated, so I went looking for a more recent compiler.

That search took me here: https://sourceforge.net/projects/open-c ... cobol/2.0/

That page offers these options:

i. Download the source and build a compiler.

ii. Use the link to the nightly build.

I took the later option and downloaded this compiler: https://sourceforge.net/projects/open-c ... z/download

2. Installation
The installation is fairly trivial. Just unzip the file into a folder and make sure the bin folder is in the PATH environment variable.

As I downloaded the 32 bit version I installed the compiler to here:

Code: Select all

C:\Program Files (x86)\OpenCOBOL\

3. Testing the Compiler
This is where things started to feel a bit like black magic.

From what I can gather the COBOL compiler will basically create a C file and it then uses a C compiler to turn that C code into the final executable.

But this process is not easy to understand as most of the documentation appears to be targeting Linux users :(

But this is what I have found out so far.

On running the compiler on a simple test.cob file I got this error:

Code: Select all

C:\Temp\>cobc -x -v test.cob
Configuration Error
C:\GNU Cobol 2.0\config\default.conf: No such file or directory

Some where in my searching for an answer I stumbled across this page: http://opencobol.add1tocobol.com/doxy/d ... ts_8h.html

The information from that page suggested running this DOS command might fix the problem:

Code: Select all

set COB_CONFIG_DIR=C:\Program Files (x86)\OpenCOBOL\config

That did fix the configuration issue but then resulted in this error:

Code: Select all

C:\Temp>cobc -x -v test.cob
Command line:   cobc -x -v test.cob
Preprocessing:  test.cob -> C:\Users\JUSSIJ~1.DES\AppData\Local\Temp\cob8840_0.cob
...
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23506 for x86
Copyright (C) Microsoft Corporation.  All rights reserved.

cob8840_0.c
C:\Temp\cob8840_0.c(14): fatal error C1083: Cannot open include file: 'libcob.h': No such file or directory

The output clearly shows the COBOL compiler is running the Microsoft compiler but some of the Microsoft compiler details are wrong.

Going back to that earlier page and it is clear there are several other environment variables that need to be set before the compiler will run.

These are all the environment variables I set to get the compiler and linker to run:

Code: Select all

set COB_CONFIG_DIR=C:\Program Files (x86)\OpenCOBOL\config
set COB_CFLAGS=-I"C:\Program Files (x86)\OpenCOBOL\include"
set COB_LIBRARY_PATH="/LIBPATH:C:\Program Files (x86)\OpenCOBOL\lib"
set COB_LIBS="C:\Program Files (x86)\OpenCOBOL\lib\libcob.lib"

With those variables in place an executable was created and it ran just fine :)

3. Final Important Details

The things to take from all of this is as follows:

i. On my system I have Visual Studio installed and have is so the cl.exe runs from the command prompt: viewtopic.php?t=2707

ii. I installed GNU COBOL into the C:\Program Files (x86)\OpenCOBOL\ folder and made sure the bin folder found in that location was in the PATH environment variable.

iii. The environment variables that I set to get the compiler to work matched this install folder location.

So depending on your configuration you might have to tweak these setting to suit.

Cheers Jussi

Return to “Tutorials, Tips and Tricks”

Who is online

Users browsing this forum: No registered users and 1 guest