### Use Your DLL (OS/2)

Write the source files that are to access your DLL as if the functions and/or variables are to be statically linked at compile time. Then when you link the program, you must inform the linker that some function and/or variable references are to a DLL and will be resolved at run time. There are two ways to communicate this information to the linker:

1. Use the ILIB utility to create a library file with all the information that the linker needs about the DLL. ILIB creates an import library (.LIB) file for the DLL. When you link an executable module, the linker uses this import library to resolve external references to the DLL.

   If your DLL contains any C++ templates, you must always access the DLL by means of an import library to ensure that the names you use when you instantiate the template are resolved correctly.

   If you invoke the linker directly, give the name of the import library where you normally specify library names. For example:

            ILINK /NOI mymain.obj finaldll.lib;

   If you invoke the linker through the `icc` command, you must put the name of the import library in the compiler invocation string. For example:

          icc mymain.c finaldll.lib

   Note: The import libraries for the IBM C and C++ Compilers runtime DLLs have been supplied with the compiler.

2. Construct a module definition file for the accessing module that is being linked. The definition file specifies which variables and names will be obtained from a DLL at run time, and in which DLLs these items will be found. In general, import libraries are easier to use and maintain than module definition files.

All DLLs must be in a directory listed in the LIBPATH environment variable or in BEGINLIBPATH or ENDLIBPATH, which prepend and append their contents to LIBPATH.

Create a DLL - An Overview