3

As per the documentation in Micro-focus support site, to call a cobol program from a C program we just need to follow the given below steps.

main(int argv, char *argv)
{

cobinit();             /* Initialize COBOL environment */

cobcall("cobep", 0, NULL); /* Call a COBOL program */

cobtidy();             /* Close down COBOL environment */

return(0);

} 

Based on this I have come up with a simple C program to call an already working Cobol program, but guess I am getting linking error.

C Program

cat call.c

#include<stdio.h> 
#include "cobcall.h" 
#include "cobmain.h" 

int main() 
{ 

int ret=0; 
cobinit(); 
ret=cobcall("cobolprogram.gnt",1,NULL); 
cobtidy(); 

return 0; 
} 

Error message receiving

gcc -Wall call.c -o call 
call.c: In function 'main': 
call.c:10: warning: pointer targets in passing argument 1 of 'cobcall'   differ in signedness 
/usr/ccs/bin/ld: Unsatisfied symbols: 
cobtidy (first referenced in /tmp/ccQBPw6r.o) (code) 
cobcall (first referenced in /tmp/ccQBPw6r.o) (code) 
cobinit (first referenced in /tmp/ccQBPw6r.o) (code) 
collect2: ld returned 1 exit status 
Braiam
  • 1
  • 11
  • 47
  • 78
Jibi Makkar
  • 63
  • 1
  • 8

1 Answers1

3

If you use MF then you likely have access to a paid support. In any case here's what I can tell you from knowing something about gcc and libraries.

The C compiler compiles fine. It only complains about signedness of a char * or const char *, but this shouldn't matter. To solve this check in the header for the actual defintion of cobcall, I assume changing it to one of these should fix the compiler warning:

ret=cobcall((char *)"cobolprogram.gnt",1,NULL); 
ret=cobcall((const char *)"cobolprogram.gnt",1,NULL);
ret=cobcall((unsigned char *)"cobolprogram.gnt",1,NULL); 
ret=cobcall((const unsigned char *)"cobolprogram.gnt",1,NULL);

Side note: as far as I know you don't pass the file extension to cobcall, therefore to make it work later you may need to remove the .gnt part.

The errors you get are from the linker as it has no possibility to resolve these mf specific functions. I've skimmed over different MF docs but did not found the library name you need. Maybe it is libcob or libcobmf or libmfcob or ...

Edit: I've found a reference in an old MF manual naming the library libcobol.

As soon as you know the library name use -lname (for example -lcobol/ -lcob/ -lcobmf/-lmfcob) to let the linker know that it can resolve them in this library. Add -L/path/to/library to let the linker know where it can find the library.

If compilation worked any your main program complains about "cannot find libcob.so" (or libcobmf.so or whatever it is named) set LD_LIBRARY_PATH to point to the library name.

Simon Sobisch
  • 6,263
  • 1
  • 18
  • 38
  • Thank you Simon for the response. – Jibi Makkar Dec 21 '16 at 13:39
  • @JibiMakkar Thank you for marking the answer as solution. I'd like to better it: What was the library name you had to use? BTW: When you start both with C (gcc) and COBOL I highly suggest to have a look at GnuCOBOL if you don't need MF explicit. – Simon Sobisch Dec 21 '16 at 14:01
  • 1
    First i compiled cobol program as follows , cob -zv "cobolprogram".cbl - it creates a shared library and then compiled c program as given below, cob -xvo "name" -CC -I$CODDIR/include "program".c In fact , i was not able to find those libraries you mentioned in my system. Then noticed cob library in your answer , that lead me to the right direction. Still i am not sure where extacly is the libraries for cobinit,cobcall and cobtidy. I believe "cob" command takes care of it. Please let me know your thoughts. – Jibi Makkar Dec 21 '16 at 18:07
  • 1
    In general it is the best way to call `cob` (or `cobc` if you switch to GnuCOBOL) as it should know best how to link the module. To check which library it used run `ldd ./program` and you see the list. If you see something that looks like a COBOL runtime retry to link with `gcc`. – Simon Sobisch Dec 22 '16 at 19:56
  • Thank you so much. – Jibi Makkar Dec 22 '16 at 22:51