I am trying to call a C++ program from a Cobol program. I have searched all over for 3.5 weeks, and this is driving me crazy. I am running CYGWIN on a windows 7 machine. My UNIX is very novice.
My c++ program computes a sha256 hash algorithm. I know it works, as i have successfully called it from another C++ program, and verified the results.
My problem is that when I try to dynamically link the main cobol program with the C++ sub program, everything looks fine on the surface. But when I execute the main program, and it calls the C++ program, I get the message displayed on the console: libcob: Cannot find module 'SUBC'.
Here are the steps I followed to compile the main program and link it with the C++ subprogram, as per OpenCobol
1.) $ cobc -x CALLSHA.cbl --- Compile the calling program
2.) $ g++ -shared -o SUBC.so SUBC.cpp --- Compile C++ sub program
3.) $ cp SUBC.so /Lib --- install the module in library directory
4.) $ export COB_LIBRARY_PATH=/Lib ---
5.) $ ./CALLSHA --- Run main program which is dynamically linked with C++ module
HERE IS THE OUTPUT FROM THE RUN:
CALL from main. --- Message produced in main program right before the call
libcob: Cannot find module 'SUBC' --- Error message says C++ program not found
Yes, I have been using those as a guide. The thing is, those compile examples are in C, not C++.
The second thing is that, my main program is a cobol program that calls a C++ program. The second link you posted is the reverse of that.
I realize that you have to use the g++ compiler instead of CC.
When I tried to compile and LINK the 2 programs "Statically", I was getting errors, even though compiling them seperately was no problem.
When I compiled and Linked them "Dynamically", I was able to get it compiled and Linked, but when the program is run, the c++ module when called by Cobol gives the error: libcob: Cannot find module 'SUBC'.
I will post the code a little later, along with the compile and link steps. I have tried many things. I never thought I would have this much trouble finding an example of a Cobol Program Calling a C++. But then again, as I said straight away, I am not a Unix guru.
And here is the C++ Sub program (Note: I change the name from SUBC, and is now called GetSha256Hash)
#include <stdio.h>
#include<iostream>
#include<vector>
#include<fstream>
#include<exception>
#include<string>
#include <cstdlib>
#ifndef C_EXTERN
#if defined (_MSC_VER) || defined (__BORLANDC__) || ( defined (WIN32) && defined (__GNUC__) )
#define C_EXTERN __declspec(dllexport)
#else
#define C_EXTERN extern
#endif
#endif
typedef unsigned int uint;
using namespace std;
C_EXTERN string fromDecimal(uint n, int b)
{
string chars="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string result="";
while(n>0)
{
result=chars.at(n%b)+result;
n/=b;
}