Next: , Previous: C Interface, Up: C Interface


2.3.1 Writing Main Program in C

Include libcob.h in your C program. Call cob_init before using any COBOL module:

     #include <libcob.h>
     
     int
     main (int argc, char **argv)
     {
       /* initialize your program */
       ...
     
       /* initialize the COBOL run-time library */
       cob_init (argc, argv);
     
       /* rest of your program */
       ...
     
       /* Clean up and terminate - This does not return */
       cob_stop_run (return_status);
     
     }

You can write cobc_init(0, NULL); if you do not want to pass command line arguments to COBOL.

You can compile your C program as follows:

     cc -c `cob-config --cflags` main.c

The compiled object must be linked with libcob as follows:

     cc -o main main.o `cob-config --libs`