DLL

Use DLL to instruct the compiler to generate an object module that is enabled for dynamic link library (DLL) support. DLL enablement is required if the program will be part of a DLL, will reference DLLs, or if the program contains object-oriented COBOL syntax such as INVOKE statements or class definitions.

Note: The DLL option can be overridden for particular CALL statements by using the CALLINTERFACE directive.

DLL option syntax

Read syntax diagramSkip visual syntax diagramNODLLDLL

Default is: NODLL

Abbreviations are: None

Link-edit considerations: COBOL programs that are compiled with the DLL option must be link-edited with the RENT and AMODE 31 link-edit options.

NODLL instructs the compiler to generate an object module that is not enabled for DLL usage.

Start of changeAMODE 64 considerations: When the LP(64) compiler option is in effect, the DLL and NODLL options are ignored and the default NODLL is effectively set because object files generated using LP(64) are always DLL enabled. They can be linked as DLL or non-DLL.End of change

Start of changeThe EXPORTALL option is supported. Use this option to export symbols from programs when building DLLs.End of change

Start of change

Example

This example shows how to build, link and run two COBOL programs, PROG1 and SUB1, on z/OS® UNIX. Program SUB1 is built as a DLL program and linked as a DLL called mylibdll.so that resides in the current z/OS UNIX directory. Program PROG1 is essentially a client of DLL mylibdll.so and makes a call to program SUB1 in the DLL.
Note: In practice, a DLL such as mylibdll.so would typically consist of many COBOL programs linked together into a DLL.
The example consists of the following files:
buildrun.sh
z/OS UNIX shell script that builds and runs the example programs
prog1.cbl
COBOL program PROG1, which makes a call to a DLL program
sub1.cbl
COBOL program SUB1, which becomes part of a DLL mylibdll.so
The buildrun.sh script is as follows:
#!/bin/sh

# Remove existing artifact files
rm -f *.o *.lst *.so *.x prog1

# Build SUB1 as a DLL program and link it into a DLL called mylibdll.so,
# which will be written to the current directory
cob2 sub1.cbl -o libmydll.so "-qdll,exportall,rent,list" -bdll

# Build PROG1 with the DLL compiler option as it will be making a call
# to program SUB1 which resides in DLL mylibdll.so, but PROG1 itself
# is not linked as a DLL -- it is linked as a non-DLL program.
# Note that PROG1 must be linked with the side deck mylibdll.x produced
# in the previous step in order for the symbol SUB1 to be resolved
cob2 prog1.cbl -o prog1 libmydll.x "-qdll,list"

# Set LIBPATH to include the current directory so that it will be
# found at runtime when PROG1 is executed
export LIBPATH=.:$LIBPATH

echo ""

# Run PROG1
./prog1
Running the buildrun.sh script produces the following output:
PP 5655-EC6 IBM Enterprise COBOL for z/OS  6.3.0 in progress ...
End of compilation 1,  program SUB1,  no statements flagged.
PP 5655-EC6 IBM Enterprise COBOL for z/OS  6.3.0 in progress ...
End of compilation 1,  program PROG1,  no statements flagged.

Entered PROG1
Calling DLL routine SUB1 from PROG1
Entered DLL routine SUB1
Exited DLL routine SUB1
Exited PROG1
After PROG1 and SUB1 are compiled and linked, the following files exist in the current z/OS UNIX directory:
buildrun.sh  libmydll.x   prog1.cbl    prog1.o      sub1.lst
libmydll.so  prog1        prog1.lst    sub1.cbl     sub1.o
prog1.cbl:

       identification division.
       program-id. prog1.
       data division.
       working-storage section.
       procedure division.
       MainProgram.
           display "Entered PROG1"
           display "Calling DLL routine SUB1 from PROG1"
           call 'SUB1'
           display "Exited PROG1"
           goback.
       end program prog1.
sub1.cbl:

       identification division.
       program-id. sub1.
       data division.
       working-storage section.
       procedure division.
       MainProgram.
           display 'Entered DLL routine SUB1'
           display 'Exited DLL routine SUB1'
           goback.
       end program sub1.
End of change

Related tasks  
Making dynamic calls

Related references  
Start of changeDynamic link libraries (DLLs)End of change
Conflicting compiler options
CALLINTERFACE (Enterprise COBOL for z/OS Language Reference)