Let's call the following COBOL module from a C program:
---- say.cob --------------------------- IDENTIFICATION DIVISION. PROGRAM-ID. say. ENVIRONMENT DIVISION. DATA DIVISION. LINKAGE SECTION. 01 HELLO PIC X(6). 01 WORLD PIC X(6). PROCEDURE DIVISION USING HELLO WORLD. DISPLAY HELLO WORLD. EXIT PROGRAM. ----------------------------------------
This program accepts two arguments, displays them, and exit.
From the viewpoint of C, this is equivalent to a function having the following prototype:
extern int say(char *hello, char *world);
So, your main program will look like as follows:
---- hello.c --------------------------- #include <libcob.h> extern int say(char *hello, char *world); int main() { int ret; char hello[6] = "Hello "; char world[6] = "World!"; cob_init(0, NULL); ret = say(hello, world); return ret; } ----------------------------------------
Compile these programs as follows:
$ cc -c `cob-config --cflags` hello.c $ cobc -c -static say.cob $ cobc -o hello hello.o say.o $ ./hello Hello World!