Using GNU COBOL with Zeus

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: 2485
Joined: Fri Aug 13, 2004 5:10 pm

Using GNU COBOL with Zeus

Post by jussij » Wed Jul 09, 2014 8:13 am

NOTE: A more up to date version of these instructions can be found here: viewtopic.php?t=7603

Overview
GNU COBOL(formerly OpenCOBOL) is a free COBOL compiler that translates COBOL code into an executable using intermediate C sources.

Details regarding the GNU Cobol compiler can be found here: https://sourceforge.net/projects/open-c ... cobol/2.0/

A user manual can be found here: http://www.opencobol.org/modules/bwiki/ ... UserManual

The FAQ is found here: http://opencobol.add1tocobol.com/gnucobol/

Setup Steps
The steps below describe how to install and setup the GNU Cobol toolset so that they can be used from inside the Zeus IDE.

These steps should also be read in conjunction with the details found here: viewtopic.php?t=7603

(1) Download the GNU Cobol 2.0 binary files found here: http://www.kiska.net/opencobol/2.0/index.html

Note: The older OpenCobol 1.1 binary files found can be found here: http://www.kiska.net/opencobol/1.1/index.html

Unzip the file to the C:\ folder and after unzipping you should see this file:

Code: Select all

C:\OpenCobol\cobc.exe
Warning: Don't try to install the software to this C:\Program Files\ or any other folder location as it will not work.

Note: You will also need some version of the Microsoft C compiler installed on the machine. The free Microsoft C/C++ Express version will do, so if you want to use that version, use Google to get the latest download link for that compiler.

Important: Make sure you choose matching 32/64 bit versions of both tools otherwise it will not work :!:

(2) Before the compiler can be run the install folder needs to be added to the PATH environment variable.

To do this add the the following folder to the PATH using the details found here.

Code: Select all

C:\OpenCobol\
To test that the path is set correctly, start Zeus and use the Tools, DOS Command Line menu and run the following command:

Code: Select all

cobc.exe -V
Running that command should result in this output:

Code: Select all

cobc (OpenCOBOL) 2.0.20120211
Copyright (C) 2001,2002,2003,2004,2005,2006,2007 Keisuke Nishida
Copyright (C) 2006-2012 Roger While
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Built     Dec 22 2013 11:01:58
Packaged  Feb 11 2012 12:36:31 UTC
C version (Microsoft) 1600
If instead you see the following it means the PATH is not set correctly so repeat the steps from the link above:

Code: Select all

'cobc.exe' is not recognized as an internal or external command,
operable program or batch file.
(3) Test the Microsoft C/C++ Compiler

For the Cobol compiler to work in needs a working Microsoft C/C++ compiler.

To check if the Microsoft C/C++ compiler is working correctly, refer to the simple test found here: viewtopic.php?f=5&t=2707&p=4936

(4) Inside Zeus, create a simple c:\temp\test.cob COBOL test file as shown below:

Code: Select all

      * Hello World Program
       IDENTIFICATION DIVISION.
       PROGRAM-ID.  "cobmain".
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  MYVAR PIC X(20).

       PROCEDURE DIVISION.
       DisplayPrompt.
           MOVE "HELLO" to MYVAR
           DISPLAY "Hello, world.".
           STOP RUN.
(5) With the c:\temp\test.cob as the active document, using the Compiler, Compile menu to compile the file should result in this output:

Code: Select all

Using document type compiler options....

cob56.c
If instead you see this, it means the Microsoft C/C++ compiler is not correctly installed, so revisit the link mentioned earlier.

Code: Select all

Using document type compiler options....

cob34.c
LINK : warning LNK4044: unrecognized option "manifest"; ignored

test.exe.manifest : general error c1010070: Failed to load and parse the manifest. The system cannot find the file specified.
Running the Executable
If the compile worked it should have also have created the c:\temp\test.exe file. To check this use the Tools, DOS Command Line menu and in the resulting dialog enter this command:

Code: Select all

dir c:\temp\test.exe
To test the executable, once again use the Tools, DOS Command Line menu but this time type in the following command:

Code: Select all

c:\temp\test.exe
This should result in the following output:

Code: Select all

Hello, world.
When it comes to running the executable from inside Zeus there are many options.

One of the easier options is to run the executable as a tool using the Tools menu or running the executable using a macro script.

For example, to run the executable via a macro edit the Macros section of the COBOL Document Type and add the following macro:

Code: Select all

 Menu Text: Execute '$fb.exe'
Macro Name: $zud\zscript\cs_exec.py
 Arguments: $fdd$fb.exe
        [x] Add to popup menu
This will allow you to run the executable using the Macros menu or the Macros tab found in the navigator panel.

For more options on how to run the executable just search the Zeus forum for details.

Cheers Jussi

jussij
Site Admin
Posts: 2485
Joined: Fri Aug 13, 2004 5:10 pm

Post by jussij » Wed Aug 13, 2014 2:31 am

Edit: The links at the top of this page link to Cobol compilers built to run with the Microsoft C compiler and not the GCC compiler.

So with the FAQ says that using gdb should be possible, this will not work for those compilers as the gdb debugger will not understand the debug information:

Code: Select all

GNU gdb (GDB) 7.7
Copyright (C) 2014 Free Software Foundation, Inc.
...
Reading symbols from CobolTest.exe...(no debugging symbols found)...done.
(gdb)
Using the GDB Debugger

The Zeus IDE has support for the gdb debugger so in theory it is possible to debug COBOL from inside Zeus.

The first thing that needs to be done is to change the compiler command line to include -g debug option:

Code: Select all

cobc.exe -g -x "$fn"
This will create an executable that contains the gdb debug info.

To debug this executable inside Zeus create new workspace using the Workspace, New menu and in the Debugging section of that workspace set the following values:

Code: Select all

     Executable: $fdd$fb.exe
Debugger Module: GDB Debugger Interface
To now run the executable inside the debugger use the Debugger menu.

Breakpoint Issue

One of the issues with the debugging COBOL code is the lines of COBOL code will noty match the debug info and as such gdb will have trouble matching the Zeus breakpoints to the COBOL code. In effect the Zeus breakpoint options will not work correctly.

The workaround to this is to use the -C option:

Code: Select all

cobc.exe -C -g -x "$fn"
This option will generate intermediate C code based on the COBOL code and this code can be used to find the correct gdb line numbers. You will need to set those breakpoints manually.

For more details on this refer to the following link: http://opencobol.add1tocobol.com/gnucobol/#id895

krigul
Posts: 9
Joined: Mon Jan 05, 2015 3:32 pm

Re: Using GNU Cobol with Zeus

Post by krigul » Fri Jan 16, 2015 12:54 am

I am trying to use the debugger, and I tried the following command
cobc.exe -C -g -x "$fn"

I created a workspace as specified, how can i set breaking points?
I can't see my program at all.

jussij
Site Admin
Posts: 2485
Joined: Fri Aug 13, 2004 5:10 pm

Re: Using GNU Cobol with Zeus

Post by jussij » Fri Jan 16, 2015 2:36 am

I can't see my program at all.
Once you setup the workspace all you need to do is use the Debugger, Start menu to start the debugger.

If you do that you should see something like this in the debug output window:

Code: Select all

Module:'c:\temp\test.exe'
Directory:'c:\temp\'
Command Line:'gdb.exe -nw --fullname c:/temp/test.exe'

GNU gdb (GDB) 7.7
Copyright (C) 2014 Free Software Foundation, Inc.
.......
how can i set breaking points?
As mention earlier COBOL spits out a C code which is then compiled.

So you have to use the earlier link to determine how to set the breakpoints and then set them manually.

They are set using the debugger command line entry field, found on the Debugger Control panel.

But I just realised, you are compiling that C code with Microsoft VC++ Express.

I'm pretty sure the gdb debugger will not work with that compiler :(

Cheers Jussi

Post Reply
kuchnie warszawa opinie

Who is online

Users browsing this forum: No registered users and 1 guest