Creating Executables that Use Library Files

You can create a system executable application file that is linked to a shared library file or includes an archive file using the -l flag on the cob -x command line. The command line should have the following form:

cob -x filenames [-L dir] [-l name]

where the parameters are:

List of the files input to the cob command.
-L dir
Changes the order in which the system linker searches for libraries that were specified with the -l cob flag.
-l name (or libname.a) is to be searched to resolve any references

This links all the application programs and subprograms with the specified libraries as well as the default COBOL run-time system libraries and operating system support libraries. The result is a system executable file that, when run, preloads the specified shared libraries before execution is passed to the main entry point.

When creating a system executable file, the code for any referenced modules that are held in shared libraries are not included in your system executable file. Instead, if such a module is referenced at run time, then the shared library is loaded into memory from the shared library file before control is passed to it.

The cob command uses a shared library in preference to an archive library of the same basename. If a cob flag names a library then cob assumes it is a shared library, but if no such library exists then it uses an archive library of the same name.

For example, if you specify two libraries abc and xyz on the cob command line as follows:

cob -x prog.cbl -labc -lxyz

where the libraries, libxyz.a and libabc.a exist, then only and libabc.a are scanned to resolve references and libxyz.a is ignored.

Bear in mind that a reference to a subprogram held in a shared library file creates a link to the whole library, whereas a reference to a subprogram held in an archive library only links to that subprogram. Unreferenced subprograms in a shared library file can be available to the dynamic loader; unreferenced subprograms in the archive library are not available to the dynamic loader.