In order to assess how I can use Tiny COBOL in forth coming projects I decided to go back to basics and start from scratch creating the ubiquitous “Hello, World!” application.
Firstly, the COBOL code itself…
IDENTIFICATION DIVISION. PROGRAM-ID. HELLO. AUTHOR. MARK HOPKINS. DATE-WRITTEN. 21 November, 2008. ENVIRONMENT DIVISION. DATA DIVISION. PROCEDURE DIVISION. DISPLAY "Hello, World!". STOP RUN.
Nice and simple, some would say overly verbose, but that’s a debate for another day. Now on to compiling it.
Tiny COBOL provides a compiler htcobol which is invoked as follows to compile the above sample to an executable file.
htcobol hello.cob
This will produce an executable called hello which when run gives the following output.
Hello, World!
Nice! Right, one thing that I’ve done in the past when working on COBOL software professionally is to build the executable with the RTS (run time system) statically linked into the executable. It means the executable is larger than it has to be but then there is no need to provide the RTS, in this case libhtcobol.so, separately; nor do we have to ensure it’s in the correct path come runtime. So how to do that with TinyCOBOL…
Looking at the htcobol man page seems to suggest the -Bmode is the way to do it (where mode is either static or dynamic) so here goes.
$ htcobol -Bstatic hello.cob /usr/bin/ld: cannot find -lhtcobol collect2: ld returned 1 exit status
Oops. Seems it can’t find the RTS. But if I run the program it works fine. Um, perhaps another option, let’s try again.
$ htcobol -Bstatic -L/usr/local/lib hello.cob /usr/bin/ld: cannot find -lhtcobol collect2: ld returned 1 exit status
Same again. As it is the ld command that seems to be complaining maybe a different option. Doing another man suggests we can get htcobol to pass parameters through to the linker. Okay, here goes…
$ htcobol -Bstatic -Wl,-L/usr/local/lib hello.cob /usr/bin/ld: cannot find -lhtcobol collect2: ld returned 1 exit status
Oh no, not again. Looking at the man page for ld seems to suggest that I need to specify the directory to the -L option where the ‘archive library’ resides. I gave it /usr/local/lib which is where the shared object sits, so try again.
$ htcobol -Bstatic -L/home/mark/work/tinycobol-0.64/lib hello.cob ... LOTS OF ERRORS ...
Double oops! Lots of errors reported time for more Googling…
Oh well, no luck there. I shall have to come back to that at another time. I am disappointed I couldn’t get it to work but hey it ain’t the end of the world…
Tags: cobol