ITEM: BL8005L
IBM COBOL and C SHARED LIBRARIES
Question:
How do you create IBM COBOL SET for AIX and C shared
libraries?
Response:
This item is being created to demonstrate using C shared
libraries and IBM COBOL SET for AIX 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 4.1.4 using IBM COBOL SET
for AIX v1.1.0.3 and C for AIX v3.1.3.8. Other version of
the products may produce different results.
The programs and shell-scripts are the following:
1) dl6a.c C-program source code
2) dl6b.c C-program source code
3) clib.sh Shell script to build a C-shared library
4) beta.cbl Cobol program source code
5) gamma.cbl Cobol program source code
6) coblib.sh Shell script to build a Cobol shared library
7) alpha.cbl Cobol program source code ( main program )
8) cobmk.sh Shell script to build the Cobol Executable
9) cfunc.exp export file
10) cob.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 reference both shared libraries. Use the cobmk.sh script.
4) Execute the program by doing ./alpha.
5) It may be necessary between builds of the shared libraries
to run the slibclean command (as root) to cleanup shared
library region.
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 NOT 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.
The programs and files are listed below:
1) dl6a.c
void
dl6a()
{static int n = 69;
printf("C dl6a function.\\n");
n = n * 10;
printf("n = %d\\n", n);
}--------------------------------------------------
2) dl6b.c
void
dl6b()
{printf("C DL6B does nothing.\\n");
}--------------------------------------------------
3) clib.sh
\#
\# Create an AIX shared library
\#
\# Tidy up
\#
rm -f scratch.a dl6a.o libcfunc.a cshr.o dl6b.o
\#
\# Make our object..
\#
xlc -cv dl6a.c dl6b.c
\#
\# Place it into a temporary library
\#
ar rv scratch.a dl6a.o dl6b.o
\#
\# Generate 'cshr.o' based on that.
\#
ld -D0 -H512 -T512 -o cshr.o scratch.a -bnoentry -bE:cfunc.exp \\
-bM:SRE -lc
\#
\# Create the shared library..
\#
ar rv libcfunc.a cshr.o
\#
\# Remove Temporary stuff.
\#
rm cshr.o dl6a.o dl6b.o scratch.a
-----------------------------------------------------
4) beta.cbl
IDENTIFICATION DIVISION.
PROGRAM-ID. "beta".
*
ENVIRONMENT DIVISION.
*
DATA DIVISION.
WORKING-STORAGE SECTION.
01 beta-msg pic x(30) value "beta to gamma".
01 beta-name pic x(8) value "BETA".
*
Linkage section.
01 msg pic x(30).
01 link-name pic x(8).
*
PROCEDURE DIVISION using msg.
DISPLAY "beta gets msg=" msg.
call "gamma" using beta-msg beta-name.
display "beta after gamma".
goback.
------------------------------------------------------------
5) gamma.cbl
IDENTIFICATION DIVISION.
PROGRAM-ID. "gamma".
*
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
*
DATA DIVISION.
WORKING-STORAGE SECTION.
01 gamma-name pic x(8).
*
Linkage section.
01 msg pic x(30).
01 link-name pic x(8).
*
PROCEDURE DIVISION using msg link-name.
DISPLAY "gamma gets msg=" msg.
if link-name = "ALPHA"
display "GAMMA defeats ", link-name
else
display "GAMMA hates ", link-name.
call "dl6b".
display "gamma after c pgm"
goback.
-------------------------------------------------------
6) coblib.sh
\#
rm -f cobshr.o libcobsub.a
cob2 -o cobshr.o beta.cbl gamma.cbl -bE:cob.exp -bM:SRE \\
-bnoentry -L`pwd` -lcfunc
ar -rv libcobsub.a cobshr.o
rm -f cobshr.o
-----------------------------------------------------------
7) alpha.cbl
IDENTIFICATION DIVISION.
PROGRAM-ID. "alpha".
*
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
*
DATA DIVISION.
WORKING-STORAGE SECTION.
01 hello1 pic x(30) value "message from alpha to beta".
01 hello2 pic x(30) value "message from alpha to gamma".
01 alpha-name pic x(8) value "ALPHA".
*
*
PROCEDURE DIVISION.
display "alpha begins"
call "beta" using hello1 alpha-name
display "alpha after beta"
call "gamma" using hello2 alpha-name
display "alpha after gamma"
call "dl6a".
display "alpha after c pgm"
display "alpha terminates"
goback.
----------------------------------------------------
8) cobmk.sh
\#
rm -f alpha
cob2 -o alpha alpha.cbl -L`pwd` -lcobsub -lcfunc
------------------------------------------------------
9) cfunc.exp
dl6a
dl6b
-------------------------------------------------------
10) cob.exp
beta
gamma
Support Line: IBM COBOL and C SHARED LIBRARIES ITEM: BL8005L
Dated: July 1996 Category: N/A
This HTML file was generated 99/06/24~13:30:21
Comments or suggestions?
Contact us