Node:Main C Program, Next:, Previous:C Interface, Up:C Interface



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 */
       ...
     }
     

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

The function cob_set_library_path will overwrite the user setting of the environment variable COB_LIBRARY_PATH.

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`