GNU Cobol 2.2 Setup Secrets

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

GNU Cobol 2.2 Setup Secrets

Post by 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 for the latest GNUCobol 2.2. release 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.2/

That page offers these options:

i. Download the source and build the compiler.

ii. Use the link to the nightly build of the compiler.

I took the last option and downloaded the nightly build zip file.

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 so I unzipped the file to this folder location:

Code: Select all

C:\Program Files (x86)\gnucobol-2.2\
This meant that the following folder was defined in the PATH environment variable:

Code: Select all

C:\Program Files (x86)\gnucobol-2.2\bin
To correctly set the path follow the instructions found here: viewtopic.php?t=6176

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)\gnucobol-2.2\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)\gnucobol-2.2\config
set COB_CFLAGS=-I"C:\Program Files (x86)\gnucobol-2.2\include"
set COB_LIBRARY_PATH="/LIBPATH:C:\Program Files (x86)\gnucobol-2.2\lib"
set COB_LIBS="C:\Program Files (x86)\gnucobol-2.2\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)\gnucobol-2.2\ 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

Post Reply
kuchnie warszawa opinie

Who is online

Users browsing this forum: No registered users and 3 guests