MicroFocus cobol commands cobinit,cobcall and cobtidy are throwing errors in my C program

691 views Asked by At

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 
1

There are 1 answers

5
Simon Sobisch On BEST ANSWER

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.