ITEM: BF3182L

MICRO FOCUS SHARED LIBRARIES and C SHARED LIBRARIES



Question:

How can MICRO FOCUS COBOL be used with COBOL shared libraries
and C shared libraries?

Response:

This item is being created to demonstrate using C shared libraries
and MICRO FOCUS COBOL shared libraries.  This item consist of C 
subroutines, COBOL subroutines, a COBOL main program, and the necessary shell scripts and export
files.  This process has been tested on AIX 3.2.5 using MICRO FOCUS 
COBOL v3.2.37 (PRN=7a.1a.11.06a) and C is 1.3.0.40.  Other version of 
MICRO FOCUS COBOL and C may produce different results.

The programs and shell-scripts are the following:

1) cfunc0.c     C-program source code
2) cfunc2.c     C-program source code
3) cfunc4.c     C-program source code
4) clib.sh     Shell script to build a C-shared library

5) COBSUB.cbl  Cobol program source code
6) COBSUB2.cbl Cobol program source code
7) coblib.sh   Shell script to build a Cobol shared library

8) COBMAIN.cbl Cobol program source code ( main program )
9) coblmk.sh   Shell script to build Cobol shared library
               and the Cobol Executable
10) cobmk.sh   Shell script to build the Cobol Executable
11) cfunc.exp   export file
12) cobsub.exp  export file

Performed the following steps:

 1) Compile and link the "C" routines into a shared library. Use the
    clib.sh script.

 2) Compile and link the COBOL sub-programs into a COBOL shared library,
    and at link time "reference" the "C" shared library.  The "C"
    shared library is not made a part of the COBOL shared library, but
    only a reference to it. Use the coblib.sh script.

 3) Compile and link the main COBOL program into an executable, and
    only reference the COBOL shared library. Use the cobmk.sh script.

Now at this time if I want to change one of the "C" routines all I
have to do is change the program, compile, and link to the "C" shared
library.  I DO NOT have to make any changes to the COBOL sub-programs
or relink, and I DO NO have to make any changes to the main COBOL
program or relink. Just execute the main program and the change
is visible.

If I want to change one of the COBOL sub-programs it is the same, just
make the change, compile and link to the COBOL shared library, no
changes are required in the main COBOL program.

1) cfunc0.c 

cfunc0()
{printf("\\r\\nC function 'cfunc0()'");
}cfunc1()
{printf("\\r\\nC function 'cfunc1()'");
}--------------------------------------------------------------------
2) cfunc2.c

cfunc2()
{printf("\\r\\nC function 'cfunc2()'");
}cfunc3()
{printf("\\r\\nC function 3");
}---------------------------------------------------------------------
3) cfunc4.c

cfunc4()
{printf("\\r\\nC function no 4");
}------------------------------------------------------------------
4) clib.sh

\#
\# Create an AIX shared library from  the C source cfunc0.c,
\# cfunc2.c and cfunc4.c
\# Tidy up
\#
rm -f scratch.a cfunc0.o cfunc2.o cfunc4.o libcfunc.a

\#
\# Make our object..
\#
xlc -c  cfunc0.c cfunc2.c cfunc4.c

\#
\# Place it into a temporary library
\#
ar rv scratch.a cfunc0.o cfunc2.o cfunc4.o

\#
\# Generate 'shr.o' based on that.
\#
ld -D0 -H512 -T512 -o shr.o scratch.a -bE:cfunc.exp -bM:SRE -lc

\#
\# Create the shared library..
\#
ar rv libcfunc.a shr.o

\#
\# Remove Temporary stuff.
\#
rm shr.o cfunc0.o cfunc2.o cfunc4.o scratch.a
------------------------------------------------------------------
5) COBSUB.cbl

       IDENTIFICATION DIVISION.
       PROGRAM-ID.  COBSUB.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 W-DAY PIC S9(4) BINARY.

       LINKAGE SECTION.
       01 RTN   PIC S9(4) BINARY.
       01 DATE1-P.
           03 S01 PIC X(8).
           03     PIC X.
       01 DATE2-P.
           03 S02 PIC X(8).
           03     PIC X.
       01 A-DAY PIC S9(5) BINARY.
       01 A-OPT PIC S9(4) BINARY.

       PROCEDURE DIVISION USING RTN DATE1-P DATE2-P A-DAY A-OPT.
       MAIN-PRG SECTION.
           display "top of COBSUB" at 0301.
           display " " at 0401.
           CALL "cfunc3".
           CALL "cfunc1".
           MOVE W-DAY       TO A-DAY.
           display "bottom of COBSUB" at 0601.
           GOBACK.
-------------------------------------------------------------------
6) COBSUB2.cbl

       IDENTIFICATION DIVISION.
       PROGRAM-ID.  COBSUB2.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 W-DAY PIC S9(4) BINARY.

       LINKAGE SECTION.
       01 RTN   PIC S9(4) BINARY.
       01 DATE1-P.
           03 S01 PIC X(8).
           03     PIC X.
       01 DATE2-P.
           03 S02 PIC X(8).
           03     PIC X.
       01 A-DAY PIC S9(5) BINARY.
       01 A-OPT PIC S9(4) BINARY.

       PROCEDURE DIVISION USING RTN DATE1-P DATE2-P A-DAY A-OPT.
       MAIN-PRG SECTION.
           display "top of COBSUB2" at 0701.
           display " " at 0801.
           CALL "cfunc4".
           CALL "cfunc2".
           MOVE W-DAY       TO A-DAY.
           display "bottom of COBSUB2" at 1001.
           GOBACK.
---------------------------------------------------------------
7) coblib.sh

\#
if [ ! -f $COBDIR/cobver ]
then
  COBDIR=/usr/lib/cobol;export COBDIR
fi
\# Make our object
\#
echo "Compiling 'cobsub.cbl' to .o"
cob -vDDxc COBSUB.cbl COBSUB2.cbl

\#
\# Place it into a temporary library..
\#
rm -f libcobsub.a
ar rv scratch.a COBSUB.o COBSUB2.o

\#
\# Generating 'shr.o' based on that..
\#
echo "Generating shr.o shared object.."
ld -v -D0 -H512 -T512 -o shr.o scratch.a -bE:cobsub.exp -bM:SRE \\
-L`pwd` -lcfunc \\
-L$COBDIR/coblib -lcobol.1.0 -lcrtn.1.0 -lc

\#
\# Create the shared library..
\#
echo "Creating shared library.."
ar rv libcobsub.a shr.o
rm -f COBSUB.o COBSUB.int COBSUB.idy scratch.a shr.o COBSUB2.o \\
COBSUB2.int COBSUB2.idy
------------------------------------------------------------------
8) COBMAIN.cbl

       IDENTIFICATION DIVISION.
       PROGRAM-ID. PMAIN.
       DATA DIVISION.

       WORKING-STORAGE SECTION.

      ****** TEST DATA : "WNA0010" *******
       01 STR1.
           03 S01 PIC X(8) VALUE "19950420".
           03     PIC X    VALUE LOW-VALUE.
       01 STR2.
           03 S02 PIC X(8) VALUE "19950430".
           03     PIC X    VALUE LOW-VALUE.
       01 A-DAY PIC S9(5) BINARY.
       01 A-OPT PIC S9(4) BINARY.
       01 RTN   PIC S9(4) BINARY.

       PROCEDURE DIVISION.

           MOVE 1 TO A-OPT.
           display space at 0101.
           display "top of COBMAIN" at 0201.
           display " " at 0301.
           CALL "COBSUB" USING RTN STR1 STR2 A-DAY A-OPT.
           CALL "COBSUB2" USING RTN STR1 STR2 A-DAY A-OPT.
           display  "bottom of COBMAIN" AT 1101.
           STOP RUN.
-------------------------------------------------------------
9) coblmk.sh

COBDIR=/usr/lib/cobol;export COBDIR
\#
\# Check briefly if we've got some kind of COBOL system available..
\#
if [ ! -f $COBDIR/cobver ]
then
     echo " The environment variable COBDIR must be set up and point"
     echo " to a suitable COBOL system to run this demo. "
     exit
fi
chmod 777 *

\#
\# Shared library must be made before building rts..
\#
echo
echo "Making the shared library 'libcobsub.a'"
sh coblib.sh

chmod 777 *
\#
\# Compile the COBOL directory to executable.
\#

cob -vdd -x COBMAIN.cbl -L`pwd` -lcobsub
rm -f COBMAIN.o COBMAIN.int

chmod 777 *
echo
echo "Now run the executable..."
echo

COBMAIN
---------------------------------------------------------------
10) cobmk.sh

COBDIR=/usr/lib/cobol;export COBDIR
\#
\# Check briefly if we've got some kind of COBOL system available..
\#
if [ ! -f $COBDIR/cobver ]
then
     echo " The environment variable COBDIR must be set up and point"
     echo " to a suitable COBOL system to run this demo. "
     exit
fi
\#
\# Compile the COBOL directory to executable.
\#

cob -vdd -x COBMAIN.cbl -L`pwd` -lcobsub
rm -f COBMAIN.o COBMAIN.int

chmod 777 *
echo
echo "Now run the executable..."
echo

COBMAIN
--------------------------------------------------------------
11) cfunc.exp

cfunc0
cfunc1
cfunc2
cfunc3
cfunc4
--------------------------------------------------------------
12) cobsub.exp

COBSUB
COBSUB2
--------------------------------------------------------------



Support Line: MICRO FOCUS SHARED LIBRARIES and C SHARED LIBRARIES ITEM: BF3182L
Dated: February 1996 Category: N/A
This HTML file was generated 99/06/24~13:30:22
Comments or suggestions? Contact us