Next: , Previous: Static Linking, Up: Multiple Sources


2.2.2 Dynamic Linking

There are two methods to achieve this. Method 1 (Using driver program). Compile all programs with the option -m:

     $ cobc -m main.cob subr.cob

This creates shared object files main.so subr.so 1.

Before running the main program, install the module files in your library directory:

     $ cp subr.so /your/cobol/lib

Set the environment variable COB_LIBRARY_PATH to your library directory, and run the main program:

     $ export COB_LIBRARY_PATH=/your/cobol/lib

Note: You may set the variable to directly point to the directory where you compiled the sources.

Now execute your program:

     $ cobcrun main

Method 2. The main program and subprograms can be compiled separately.

The main program is compiled as usual:

     $ cobc -x -o main main.cob

Subprograms are compiled with the option -m:

     $ cobc -m subr.cob

This creates a module file subr.so 2.

Before running the main program, install the module files in your library directory:

     $ cp subr.so /your/cobol/lib

Now, set the environment variable COB_LIBRARY_PATH to your library directory, and run the main program:

     $ export COB_LIBRARY_PATH=/your/cobol/lib
     $ ./main

Footnotes

[1] The extension varies depending on your host.

[2] The extension varies depending on your host.