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
./configure
make
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!

       IDENTIFICATION DIVISION.
       PROGRAM-ID. LOW-END-SAMPLE.
       AUTHOR. 	raindog308.

       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       SOURCE-COMPUTER. 
       OBJECT-COMPUTER.
       INPUT-OUTPUT SECTION.
              
       DATA DIVISION.
       FILE SECTION.
   
       WORKING-STORAGE SECTION.

       PROCEDURE DIVISION.
       0001-HELLO.
           DISPLAY "LowEnd4Life!".
           			
           STOP RUN.
           
           END PROGRAM LOW-END-SAMPLE.

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
LowEnd4Life!
$

 

raindog308

1 Comment

  1. lol :/ Well, *I* am glad you took the time to write thgis :P

    Cheers/Bill

    MacPro 5,1 –>
    System:
    Kernel: 6.6.13+bpo-amd64 arch: x86_64 bits: 64 compiler: gcc v: 12.2.0 Desktop: Cinnamon v: 5.6.8
    wm: muffin dm: LightDM Distro: Debian GNU/Linux 12 (bookworm)
    Machine:
    Type: Desktop System: Apple product: MacPro5,1 v: 0.0 serial: Chassis: type: 7
    v: Mac-F221BEC8 serial:
    Mobo: Apple model: Mac-F221BEC8 serial: UEFI: Apple v: MP51.88Z.0089.B00.1806081708
    date: 06/08/18
    CPU:
    Info: 2x 6-core model: Intel Xeon X5670 bits: 64 type: MT MCP SMP arch: Nehalem rev: 2 cache:
    L1: 2x 384 KiB (768 KiB) L2: 2x 1.5 MiB (3 MiB) L3: 2x 12 MiB (24 MiB)
    Speed (MHz): avg: 2327 high: 3059 min/max: 1596/3059 boost: enabled cores: 1: 1596 2: 3059
    3: 1596 4: 3059 5: 1596 6: 3059 7: 1596 8: 3059 9: 1596 10: 3059 11: 1596 12: 3059 13: 1596
    14: 3059 15: 1596 16: 3059 17: 1596 18: 3059 19: 1596 20: 3059 21: 1596 22: 3059 23: 1596
    24: 3059 bogomips: 140457
    Flags: ht lm nx pae sse sse2 sse3 sse4_1 sse4_2 ssse3 vmx
    Graphics:
    Device-1: AMD Juniper XT [Radeon HD 5770] vendor: Apple MacPro5 1 driver: N/A arch: TeraScale-2
    pcie: speed: 5 GT/s lanes: 16 bus-ID: 05:00.0 chip-ID: 1002:68b8
    Display: x11 server: X.Org v: 1.21.1.7 driver: X: loaded: vesa
    unloaded: fbdev,modesetting,radeon dri: swrast gpu: N/A display-ID: :0 screens: 1
    Screen-1: 0 s-res: 1920×1080 s-dpi: 96
    Monitor-1: default res: 1920×1080 size: N/A
    API: OpenGL v: 4.5 Mesa 22.3.6 renderer: llvmpipe (LLVM 15.0.6 128 bits) direct-render: Yes
    Audio:
    Device-1: Intel 82801JI HD Audio driver: snd_hda_intel v: kernel bus-ID: 00:1b.0
    chip-ID: 8086:3a3e
    Device-2: AMD Juniper HDMI Audio [Radeon HD 5700 Series] vendor: Apple driver: snd_hda_intel
    v: kernel pcie: speed: 5 GT/s lanes: 16 bus-ID: 05:00.1 chip-ID: 1002:aa58
    API: ALSA v: k6.6.13+bpo-amd64 status: kernel-api with: aoss type: oss-emulator
    Server-1: PipeWire v: 0.3.65 status: n/a (root, process) with: 1: pipewire-pulse status: active
    2: wireplumber status: active 3: pipewire-alsa type: plugin 4: pw-jack type: plugin
    Network:
    Device-1: Intel 82574L Gigabit Network driver: e1000e v: kernel pcie: speed: 2.5 GT/s lanes: 1
    port: 2000 bus-ID: 09:00.0 chip-ID: 8086:10f6
    IF: eth0 state: down mac:
    Device-2: Intel 82574L Gigabit Network driver: e1000e v: kernel pcie: speed: 2.5 GT/s lanes: 1
    port: 1000 bus-ID: 0a:00.0 chip-ID: 8086:10f6
    IF: eth1 state: down mac:
    Device-3: Broadcom BCM4322 802.11a/b/g/n Wireless LAN vendor: Apple AirPort Extreme driver: wl
    v: kernel pcie: speed: 2.5 GT/s lanes: 1 bus-ID: 0d:00.0 chip-ID: 14e4:432b
    IF: wlan0 state: up mac:
    Bluetooth:
    Device-1: Apple Built-in Bluetooth 2.0+EDR HCI type: USB driver: btusb v: 0.8 bus-ID: 5-1.1:3
    chip-ID: 05ac:8215
    Report: hciconfig ID: hci0 rfk-id: 1 state: up address: bt-v: 1.2 lmp-v: 2.1
    sub-v: 21d0
    Drives:
    Local Storage: total: 412.7 GiB used: 16.93 GiB (4.1%)
    ID-1: /dev/sda vendor: Hitachi model: HDS721032CLA362 size: 298.09 GiB speed: 3.0 Gb/s
    serial:
    ID-2: /dev/sdb type: USB vendor: SanDisk model: USB 3.2Gen1 size: 114.61 GiB serial:
    Partition:
    ID-1: / size: 189.98 GiB used: 6.25 GiB (3.3%) fs: ext4 dev: /dev/sda2
    ID-2: /boot/efi size: 299.4 MiB used: 9.8 MiB (3.3%) fs: vfat dev: /dev/sda1
    Swap:
    ID-1: swap-1 type: partition size: 103.71 GiB used: 0 KiB (0.0%) priority: -2 dev: /dev/sda3
    ID-2: swap-2 type: zram size: 89.58 GiB used: 0 KiB (0.0%) priority: 100 dev: /dev/zram0
    Sensors:
    System Temperatures: cpu: 48.0 C mobo: 43.5 C
    Fan Speeds (RPM): N/A
    Repos:
    Packages: 1784 pm: dpkg pkgs: 1782 pm: flatpak pkgs: 2
    Active apt repos in: /etc/apt/sources.list
    1: deb https: //deb.debian.org/debian/ bookworm main contrib non-free non-free-firmware
    2: deb https: //security.debian.org/ bookworm-security main contrib non-free non-free-firmware
    3: deb https: //deb.debian.org/debian/ bookworm-updates main contrib non-free non-free-firmware
    4: deb https: //deb.debian.org/debian/ bookworm-backports main contrib non-free non-free-firmware
    Active apt repos in: /etc/apt/sources.list.d/spirallinux.list
    1: deb https: //fasttrack.debian.net/debian-fasttrack/ bookworm-fasttrack main contrib non-free
    2: deb https: //fasttrack.debian.net/debian-fasttrack/ bookworm-backports-staging main contrib non-free
    Info:
    Processes: 414 Uptime: 46m Memory: 94.29 GiB used: 19.36 GiB (20.5%) Init: systemd v: 252
    target: graphical (5) default: graphical Compilers: gcc: 12.2.0 alt: 12 Client: Sudo v: 1.9.13p3
    inxi: 3.3.26

    May 20, 2024 @ 1:42 am | Reply

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 *