C Wrapper for Calling Library Function


This is sort of a 'cheat', but might be useful to someone.

I was not having luck getting a call to the crc32 function included in zlib to link correctly.  As it turns out Ubuntu (and its derivatives) have broken the linking mechanism that GnuCOBOL uses.  Brian Tiffin gave me some pointers and I did get the link to work, sort of, except that I never could get the value back from the function into my GnuCOBOL program the way I needed it.  This is most likely my own shortcomings, as I can barely spell 'C' even after successfully completing four college courses requiring me to utilize C/C++ for the lab work.  Hey, I think I remember garnering either A's or B's for all of those courses, but it was decades ago and I just never utilized the language much after completing the course work.

Anyway, I decided I knew enough C to write a rudimentary subprogram to accept a call from my main GnuCOBOL program, dynamically call the function I needed from zlib, and return the value to the main program.  And it works very well.  I no longer have to worry about whether the linking mechanism works for the version of GnuCOBOL and Linux combination I am currently working under, so this should work from now on.  I may even need to use it for other functions.

To install the source programs (the wrapper and a simple test COBOL program), and compile them, execute the bash script:  WrapCRC32setup [md5: e13142289f18e0b9eb18f16329140f15].  Right click and save the script in the location where you want the source programs to reside, then execute it.  It will create two files containing the source programs, then execute the GnuCOBOL compiler to compile them into the run unit for the test program.  The GnuCOBOL compiler must be installed prior to executing the bash script.  

Output from the test/verification program:

jay@Phoenix $ ./testCRC
COBOL BUFFER:The quick brown fox jumped over the sleeping black dog!
COBOL CRC:-1852367709

This page was last updated on May 24, 2016.