LowEndBox - Cheap VPS, Hosting and Dedicated Server Deals

Was I Serious? How to Install GnuCOBOL on Debian 11

COBOL CODERecently someone on LowEndTalk mentioned asmbb, which is forum software written in assembler.

Full stop.

Written in assembler.  Forum software.

Go look – it’s actually pretty nice.

I joked that I was inspired to write forum software in COBOL.  Was I serious?  Well…not exactly, but it would be fun.

COBOL gets a bad rap – and deservedly so!  It’s overly verbose to the point of being a parody of itself, and is very rigid in its views of programming.  It’s designed to execute top down (“gravity driven design” is the term) and while in theory you can program anything in it, the real strength is in high speed processing of records.  If you’ve got a bunch of records on tape 1 and want to transform them and put them on tape 2, COBOL is your go-to.

I say high speed because for years, IBM designed their mainframes with COBOL in mind and there is a tight symbiotic relationship between big iron and COBOL.  On average, each sentence in COBOL (despite its sentence-long verbosity) generates only 4 assembler instructions, and since variables are pre-defined it’s easy to optimize the hell out of the code.  COBOL was designed when memory was written in kilobytes and its “records batch processing” mindset makes it lean and mean.

And I say record-oriented because this is COBOL’s niche.  As the announcement last year for the new gcobol project (a parallel to GnuCOBOL) stated:

Cobol has a niche no other language occupies: a compiled language for record-oriented I/O.

That might sound strangely specialized, but it’s not. Record-oriented I/O describes, I would argue, nearly *all* applications. Yet, since the advent of C, nearly all applications have relegated I/O to an external library, and adopted the Unix byte-stream definition of a “file”.

If you’ve written a CGI web application, you know what I’m talking about. Cobol eliminates a lot of gobbledygook by reducing free-form run-time variables to compile-time constants.

I’m not about to recommend anyone learn COBOL in 2023.  While there are still hundreds of millions of lines of COBOL code in use, no one is writing new systems in COBOL these days.

But if into vintage systems…

To that end, I googled for a tutorial on how to setup GNU Cobol on Debian 11 and couldn’t find one.  It was in sid, but was dropped, and while there are some third-party .debs out there, it’s pretty straightforward to build from scratch.

First, install some basics and dependencies:

apt-get -y install build-essential libgmp-dev libdb-dev libncurses-dev \
  libcjson-dev libxml2-dev

Next, download the Gnu COBOL package and untar it.  The project’s page is on SourceForge, but the FTP site is more direct.  Here I’m using 3.1.2 but check for the latest:

cd /usr/local/src
wget https://ftp.gnu.org/gnu/gnucobol/gnucobol-3.1.2.tar.gz
cd gnucobol-3.1
make install

This gives you everything you might normally need:

configure: Dynamic loading: System
configure: Use gettext for international messages: yes
configure: Use fcntl for file locking: yes
configure: Use math multiple precision library: gmp
configure: Use curses library for screen I/O: ncursesw
configure: Use Berkeley DB for INDEXED I/O: yes
configure: Used for XML I/O: libxml2
configure: Used for JSON I/O: cjson

Read the DEPENDENCIES file if you want some more exotic options or have specialized needs.

Here’s some code to try…and yes, those leading spaces are significant.  This program could be shortened but shortening code is not the COBOL mindset!

       AUTHOR. 	raindog308.


           DISPLAY "LowEnd4Life!".
           STOP RUN.

Make sure you have /usr/local/lib in your LD_LIBRARY_PATH, since that’s where you installed the COBOL libraries (.so files) by default.  You can stick this in your .bash_profile:

export LD_LIBRARY_PATH=${LOAD_LIBRARY_PATH}:/usr/local/lib

And the compile and go:

$ cobc -x lowend.cbl
$ ./lowend


No Comments

    Leave a Reply

    Some notes on commenting on LowEndBox:

    • Do not use LowEndBox for support issues. Go to your hosting provider and issue a ticket there. Coming here saying "my VPS is down, what do I do?!" will only have your comments removed.
    • Akismet is used for spam detection. Some comments may be held temporarily for manual approval.
    • Use <pre>...</pre> to quote the output from your terminal/console, or consider using a pastebin service.

    Your email address will not be published. Required fields are marked *