美文网首页
c程序如何调用cobol gnt程序

c程序如何调用cobol gnt程序

作者: CodingCode | 来源:发表于2022-11-08 13:34 被阅读0次
    1. c程序
    $ cat main.c
    #include <stdio.h>
    #include <string.h>
    
    #include "cobmain.h"
    #include "cobcall.h"
    #include "cblproto.h"
    
    int main(int argc, char *argv[])
    {
        printf("entry of main\n");
    
        cobinit();                      /* Initialize COBOL environment */
        cobcall("HELLOWORLD", 0, NULL); /* Call a COBOL program */
        cobtidy();                      /* Close down COBOL environment */
    
        return(0);
    }
    
    1. cobol程序
    $ cat HELLOWORLD.cbl
           IDENTIFICATION DIVISION.
           PROGRAM-ID. HELLOWORLD.
           ENVIRONMENT DIVISION.
           DATA DIVISION.
           WORKING-STORAGE SECTION.
    
           PROCEDURE DIVISION.
           BEGIN-PGM.
               DISPLAY "HELLO WORLD!".
    
               STOP RUN.
    
    1. makefile
    $ cat makefile.main
    
    COBDIR=/opt/microfocus/cobol5.1
    DB2DIR=/opt/ibm/db2/V9.7
    
    all: HELLOWORLD.gnt main
    
    .SUFFIXES: .cbl .gnt
    
    .cbl.gnt:
        cob -ug $*.cbl -C "use(opt.dir)" -C "list($*.lst)" -C XREF -C SETTINGS
    
    main: main.c
        gcc -o $@ -I${COBDIR}/include -L${COBDIR}/lib -lcobrts64 -lcobcrtn64 -lcobmisc64 -lcobscreen64 -ldl $<
    
    clean:
        -rm -rf c *.lst *.lis *.int *.idy *.so *.gnt *.o *.bnd core.* main
    
    1. 编译运行
    $ make
    $ ./main
    entry of main
    HELLO WORLD!
    

    相关文章

      网友评论

          本文标题:c程序如何调用cobol gnt程序

          本文链接:https://www.haomeiwen.com/subject/kflntdtx.html