[next] [previous] [contents]

  21.4.2 Accessing Shareable Images at DCL Level
  To access a shareable image at DCL level, follow these steps:

  1. Write and compile a program unit that is to be inserted
        into a shareable image.
  2. Create an options file required for the link operation.
  3. Link the program with the /SHAREABLE qualifier, and
        specify the options file with the /OPTION qualifier.
  4. Write a main program that accesses the routine in the
        shareable image.
  5. Compile the main program, and link it with the shareable
        image.

  The following example shows how to access a shareable
  image at the DCL level by performing these steps:

  1. Write and compile a program unit that is to be inserted
        into a shareable image.
        !Program name - ADD.BAS
        FUNCTION REAL ADD (LONG A, LONG B)
        ADD = A + B
        FUNCTIONEND
  2. Create an options file that will export the function for the
        link operation.

        VAX BASIC
        !Program name - ADDSUB.OPT
        UNIVERSAL = ADD

        DEC BASIC
        ! Program name - ADDSUB.OPT
        SYMBOL_ADDER = (ADD=PROCEDURE)
  3. Link the program with the qualifiers /SHAREABLE and
        /OPTION.
        $ LINK/SHAREABLE ADD, ADDSUB/OPTION

        Copy the shareable image to SYS$SHARE:, or define
        a logical name to the full image file specification. For
        example,
        $ Define ADD Sys$Login:Add.exe
  4. Write a main program that accesses the routine in the
        shareable image.
        !Program name - CALLADD.BAS
        EXTERNAL REAL FUNCTION ADD (LONG, LONG)
        DECLARE LONG X,Y
        X = 1
        Y = 2
        PRINT ADD(X,Y)
        END

  5. Compile the main program, and link it with the shareable
        image.
  $ LINK CALLADD,ADDMAIN/OPTION

  To link CALLADD with the shareable image ADD, you must
  have a linker options file specifying that ADD is a shareable
  image. For example:
  !Options file - ADDMAIN.OPT
  ADD/SHAREABLE

  Next, execute the program. Upon executing the program, the
  image activator attempts to locate the shareable image in the
  directory SYS$SHARE:. If you want the image activator to
  access a shareable image outside SYS$SHARE:, you must de-
  fine a logical name to the shareable image before you execute
  the program. Define the full file specification of the shareable
  image to the name of the shareable image, as follows:
  $ DEFINE MYSHR DISK$WORKDISK:[MYDIR]MYSHR.EXE

  This is a simple example of using shareable images. For a
  more thorough understanding of shareable images, see the
  OpenVMS Linker Utility Manual
and the Guide to Creating
  Modular Procedures.



                                            Note

        On OpenVMS VAX, using the linker option
        UNIVERSAL = to export routines is not recom-
        mended.