Creating Shared Libraries

Shared libraries cannot be directly executed. They need to be linked into a system executable or callable shared object. A shared library name must always start with the prefix lib and have the extension .so.

By default, cob creates a shared library name of, where name is the base-name of the first application supplied to cob. For example, the following command compiles the program myprog.cbl to native object code and then links it to create a shared library

cob -Z myprog.cbl

A shared library file is not executable itself. It must be linked into a system executable using the -l flag on the cob command line. For example, the following command creates a system executable myapp that loads when it is run.

cob -x myapp.o -L. -lmyprog

A shared library can be created from a combination of COBOL, C and C++ source files, .int files or any type of .o files. For example, the following command compiles the COBOL programs myprog.cbl and to native object code, compiles the C source file mysub.c to an object file and then links them together to create the shared library

cob -Z myprog.cbl csub.c -o

If any C++ code is linked into a shared library, the cob -Z,CC flag should be used so that the C++ compiler (and not the system linker) creates the shared library file. For example, the following command: creates the shared library using the COBOL programs myprog.cbl and, the C source file csub.c, and the C++ source file cppsub.C

cob -Z,CC myprog.cbl csub.c cppsub.C