Categories
Deals Programming Reading Material

A quick and dirty guide to installing a COBOL compiler and IDE on macOS (and get a COBOL book at a discount)

OpenCobolIDE running on macOS, displaying the code for the “Chunky Bacon” version of “Hello, World!”.

OpenCobolIDE running on my MacBook Pro. Tap the screen shot to see it at full size.

In an earlier post, I played around with an online COBOL compiler. Seeing as I’m a COVID-19 unemployment statistic and there’s a call for COBOL developers to help shore up ancient programs that are supposed to be issuing relief checks, I’ve decided to devote a little more time next week (this week, I have to finish revising a book) to playing with the ancient programming language. I’ll write about my experiences here, and I’ll also post some videos on YouTube.

If you want to try your hand at COBOL on the Mac, you’re in luck: it’s a lot easier than I expected it would be!

Get the compiler: GnuCOBOL

COBOL isn’t used much outside enterprise environments, which means that COBOL compilers and IDEs are sold at enterprise prices. If you’re an individual programmer without the backing of a company with a budget to pay for developer tools, your only real option is GnuCOBOL.

On macOS, the simplest way to install GnuCOBOL is to use Homebrew.

If Homebrew isn’t already installed on your system (and seriously, you should have it if you’re using your Mac as a development machine), open a terminal window and enter this to install it:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

If Homebrew is installed on your system, first make sure that it’s up to date by using this command in a terminal window:

brew update

Then install GnuCOBOL by entering the following:

brew install gnu-cobol

Once that’s done, GnuCOBOL should be on your system under the name cobc. You can confirm that it’s on your system with the following command…

cobc -v

…which should result in a message like this:

cobc (GnuCOBOL) 2.2.0
Built Aug 20 2018 15:48:14 Packaged Sep 06 2017 18:48:43 UTC
C version "4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.10.43.1)"
loading standard configuration file 'default.conf'
cobc: error: no input files

Get the IDE: OpenCobolIDE

Unless you’ve got some way to configure your text editor to deal with the language’s quirks, you really want to use an IDE when coding in COBOL. Once again, an open source project comes to the rescue: OpenCobolIDE.

OpenCobolIDE relies on Python 3, so make sure you’ve installed Python 3 before installing OpenCobolIDE. I installed it on my computer by installing the Python 3 version of Anaconda Individual Edition.

If Python 3 is already on your system, you have a couple of options for installing OpenCobolIDE:

  1. Installing OpenCobolIDE using the Python 3 package installer, pip3, which gives you a program that you launch via the command line. This gives you OpenCobolIDE version 4.7.6.
  2. Downloading the .dmg disk image file, which gives you an app lives in the Applications folder and which you launch by clicking an icon. This gives you OpenCobolIDE version 4.7.4.

I strongly recommend going with option 1. OpenCobolIDE is no longer maintained, so you might as well go with the latest version, which you can only get by installing it using Homebrew. Version 4.7.6 has a couple of key additional features that you’ll find handy, including:

  • Support for all the COBOL keywords in GnuCOBOL 2.x. This is a big deal in COBOL, which has something in the area of 400 reserved words. For comparison, C and Python have fewer than 40 reserved words each.
  • Better indentation support (and you want that in COBOL, thanks to its ridiculous column rules from the 1960s).
  • Support for compiler flags like -W and -Wall — and hey, warning flags are useful!

To install OpenCobolIDE using the Python 3 package installer, pip3, enter the following in a terminal window:

pip3 install OpenCobolIDE --upgrade

To launch OpenCobolIDE, enter this:

OpenCobolIDE

You’ll be greeted with this window:

Tap New file. You’ll see this:

For Template, select Program, enter the name and location for your program file, and tap OK.

You should see this:

Tap the screen shot to see it at full size.

Don’t mistake those red vertical lines for glitches. They’re column guides. COBOL is from the days of punched cards, and is one of those programming languages that’s really fussy about columns:

  • The first 6 columns are reserved for sequence numbers.
  • Column 7 is reserved for a line continuation character, an asterisk (which denotes a comment) or another special character.
  • Columns 8 through 72 are for code, and are broken down into 2 zones:
    • Area A: Columns 8 through 11, which are used for DIVISIONS, SECTIONS, and PARAGRAPHS, as well as specifying levels 01 through 77 (COBOL is weird).
    • Area B: Columns 12 through 72, which is for the rest of the code.
  • Columns 73 through 80 make up the “identification” area and are ignored by the compiler. It’s useful for very short comments along the lines of “TODO” or “HACK”.

Get the book: Beginning Cobol for Programmers

There aren’t many current books on COBOL out there. Apress’ Beginning COBOL for Programmers is probably the best of the bunch, and unlike many old COBOL books, makes sense to developers with a solid grounding in modern programming languages.

The ebook is available for US$49.99, but if you use the coupon code SPRING20A by the end of Thursday, April 16, you can get a $20 discount, reducing the price to $29.99. If you want the book for this price, take action before it’s too late!

Are you looking for someone with both strong development and “soft” skills? Someone who’s comfortable either being in a team of developers or leading one? Someone who can handle code, coders, and customers? Someone who can clearly communicate with both humans and technology? Someone who can pick up COBOL well enough to write useful articles about it on short notice? The first step in finding this person is to check out my LinkedIn profile.

7 replies on “A quick and dirty guide to installing a COBOL compiler and IDE on macOS (and get a COBOL book at a discount)”

I was a Cobol developer for almost 34 years and recently installed it on my MacBook, but not IDE for two reasons:
a) love to create my own templates etcetera
b) does not work exactly as you described
Thank you very much indeed for informing us how to reuse old-school skills next and in addition to the more modern ones!

Hi,
this is exactly what I’ve been looking for. I followed your instructions to the letter and unfortunately ended up with this output:
/usr/local/bin/opencobolide ; exit;
/usr/local/bin/opencobolide ; exit;
Traceback (most recent call last):
File “/usr/local/lib/python3.9/site-packages/open_cobol_ide/extlibs/pyqode/qt/__init__.py”, line 109, in autodetect
import PyQt5
ModuleNotFoundError: No module named ‘PyQt5’

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/usr/local/lib/python3.9/site-packages/open_cobol_ide/extlibs/pyqode/qt/__init__.py”, line 116, in autodetect
import PyQt4
ModuleNotFoundError: No module named ‘PyQt4’

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/usr/local/lib/python3.9/site-packages/open_cobol_ide/extlibs/pyqode/qt/__init__.py”, line 122, in autodetect
import PySide
ModuleNotFoundError: No module named ‘PySide’

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/usr/local/bin/opencobolide”, line 33, in
sys.exit(load_entry_point(‘OpenCobolIDE==4.7.6’, ‘gui_scripts’, ‘opencobolide’)())
File “/usr/local/lib/python3.9/site-packages/open_cobol_ide/main.py”, line 29, in main
from pyqode.qt import QtGui
File “/usr/local/lib/python3.9/site-packages/open_cobol_ide/extlibs/pyqode/qt/__init__.py”, line 156, in
autodetect()
File “/usr/local/lib/python3.9/site-packages/open_cobol_ide/extlibs/pyqode/qt/__init__.py”, line 126, in autodetect
raise PythonQtError(‘No Qt bindings could be found’)
pyqode.qt.PythonQtError: No Qt bindings could be found

I see that it is not finding the PyQt5 libs but I am new to Mac OS X unix and unable to see why its not working. I have enabled the root account and find that even executing the OpenCobolIde command in the terminal still fails.
Any help will be most welcomed.
Best Regards
Stephen. Ex VSII IBM Mainframe Cobol programmer.

I have used your useful instructions with my previous Mac with satisfaction. Now I have the new Mac m1 (iMac) and the don’t work.
The following is what happen:
maurizioamari@iMacdiMaurizio ~ % /bin/bash -c “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)”
==> Checking for `sudo` access (which may request your password)…
Password:
==> This script will install:
/opt/homebrew/bin/brew
/opt/homebrew/share/doc/homebrew
/opt/homebrew/share/man/man1/brew.1
/opt/homebrew/share/zsh/site-functions/_brew
/opt/homebrew/etc/bash_completion.d/brew
/opt/homebrew

Press RETURN to continue or any other key to abort:
==> /usr/bin/sudo /usr/sbin/chown -R maurizioamari:admin /opt/homebrew
==> Downloading and installing Homebrew…
HEAD is now at 82550edf6 Merge pull request #12838 from Homebrew/dependabot/bundler/Library/Homebrew/sorbet-0.5.9613
Updated 2 taps (homebrew/core and homebrew/cask).
==> Installation successful!

==> Homebrew has enabled anonymous aggregate formulae and cask analytics.
Read the analytics documentation (and how to opt-out) here:
https://docs.brew.sh/Analytics
No analytics data has been sent yet (nor will any be during this install run).

==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
https://github.com/Homebrew/brew#donations

==> Next steps:
– Run these two commands in your terminal to add Homebrew to your PATH:
echo ‘eval “$(/opt/homebrew/bin/brew shellenv)”‘ >> /Users/maurizioamari/.zprofile
eval “$(/opt/homebrew/bin/brew shellenv)”
– Run brew help to get started
– Further documentation:
https://docs.brew.sh

maurizioamari@iMacdiMaurizio ~ % brew update
Already up-to-date.
maurizioamari@iMacdiMaurizio ~ % brew install gnu-cobol
Warning: gnu-cobol 3.1.2 is already installed and up-to-date.
To reinstall 3.1.2, run:
brew reinstall gnu-cobol
maurizioamari@iMacdiMaurizio ~ % brew reinstall gnu-cobol
==> Downloading https://ghcr.io/v2/homebrew/core/gnu-cobol/manifests/3.1.2-1
Already downloaded: /Users/maurizioamari/Library/Caches/Homebrew/downloads/242840bc27b90f9592999966b9e7b15dc0c81cead90a703a2a0535cac22ba2df–gnu-cobol-3.1.2-1.bottle_manifest.json
==> Downloading https://ghcr.io/v2/homebrew/core/gnu-cobol/blobs/sha256:84862844
Already downloaded: /Users/maurizioamari/Library/Caches/Homebrew/downloads/260f05fe8ffb2728d318d2f8e09a292969944d7111249adee7194355c4aef663–gnu-cobol–3.1.2.arm64_monterey.bottle.1.tar.gz
==> Reinstalling gnu-cobol
==> Pouring gnu-cobol–3.1.2.arm64_monterey.bottle.1.tar.gz
/opt/homebrew/Cellar/gnu-cobol/3.1.2: 64 files, 2.7MB
==> Running `brew cleanup gnu-cobol`…
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
maurizioamari@iMacdiMaurizio ~ % cobc -v
cobc (GnuCOBOL) 3.1.2.0
Built Oct 29 2021 07:50:17 Packaged Dec 23 2020 12:04:58 UTC
C version “Apple LLVM 13.0.0 (clang-1300.0.29.3)”
loading standard configuration file ‘default.conf’
cobc: error: no input files
maurizioamari@iMacdiMaurizio ~ % pip3 install OpenCobolIDE –upgrade
DEPRECATION: Configuring installation scheme with distutils config files is deprecated and will no longer work in the near future. If you are using a Homebrew or Linuxbrew Python, please see discussion at https://github.com/Homebrew/homebrew-core/issues/76621
Requirement already satisfied: OpenCobolIDE in /opt/homebrew/lib/python3.9/site-packages (4.7.6)
WARNING: You are using pip version 21.3.1; however, version 22.0.3 is available.
You should consider upgrading via the ‘/opt/homebrew/opt/python@3.9/bin/python3.9 -m pip install –upgrade pip’ command.
maurizioamari@iMacdiMaurizio ~ % OpenCobolIDE
zsh: command not found: OpenCobolIDE
maurizioamari@iMacdiMaurizio ~ %
Thank you in advance if you can help me.
Maurizio Amari

Thank you for the time you are spending for my problem.
Two days ago I have tried to install Opencobolide by following the option2, specified in your guide, and I have successful installed Opencobolide. But when I open it appears the following message
“Failed to find a working GnuCOBOL compiler!
The IDE will continue to work but you won’t
be able to compile..”
Through the preferences of the Opencobolide there the possibilities to specify the “compiler path” bat I don’t where to find this path of the gnu-cobol installed through the terminal procedure.

Comments are closed.