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 libname.so, 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 libmyprog.so.

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 libmyprog.so 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 mysub.int 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 libmyapp.so.

cob -Z myprog.cbl mysub.int csub.c -o libmyapp.so

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 libmyprog.so using the COBOL programs myprog.cbl and mysub.int, the C source file csub.c, and the C++ source file cppsub.C

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