Linkage Provisions

Entry points declared in a calling program are linked to corresponding entry points provided by a library in one of three ways:

  • Directly

  • Indirectly

  • Dynamically

The library program specifies the form of linkage. Indirect and dynamic linkages allow linkage to be established to libraries other than the library specified by the calling program. The calling program can control the library invocation to which it is linked only by specifying the object code file title or the function name of the library or, for dynamic linkage, by specifying the LIBPARAMETER library attribute. Depending on the value of the LIBACCESS library attribute, the TITLE attribute or FUNCTIONNAME attribute is used to specify the object code file title of the library. For more information about library attributes, see Library Attributes.

Direct linkage occurs when the library program contains the procedure that is named in the EXPORT declaration of the library.

Indirect linkage occurs when the library program exports a procedure that is declared as an entry point of another library. The operating system then attempts to link the calling program to this second library, which can provide the entry point directly, indirectly, or dynamically.

Dynamic linkage allows a library program to determine at link time which library task the calling program will be linked to. The library program must provide a selection procedure that accepts the value of the LIBPARAMETER library attribute as a parameter. Based on the value of LIBPARAMETER, the selection procedure selects and initiates a library task. The selection procedure must also accept, as a second parameter, a procedure. This procedure, which is provided by the operating system to verify that the library task is valid and complete, must be called before the selection procedure is exited. The operating system calls the selection procedure at link time. For a more detailed explanation and examples of libraries that provide dynamic linkage, see Library Examples.

The restrictions on the complexity of indirect and dynamic linkages are as follows:

  • Eventually, a library must provide the entry point directly.

  • The chain of referenced libraries must never become circular.