### Create Your Own Subsystem Runtime Library

To create your own subsystem runtime library, follow these steps:

1. Copy and rename the IBM C and C++ Compilers CPPRNI36.DEF file (for example, to mysdll.def.) You must also change the DLL name on the LIBRARY line of the module definition file.
   CPPRNI36.DEF is installed in IBMCXXW/LIB
   CPPRNI36.DEF is installed in IBMCXXO/LIB
2. Remove any functions that you do not use directly or indirectly (through other functions) from your renamed module definition file, including the STUB line. Do not delete anything with the comment **** next to it; variables and functions indicated by this comment are used by startup functions and are always required.
3. Create a source file for your DLL, for example, mysdll.c. If you are creating a runtime library that contains only IBM C and C++ Compilers functions, create an empty source file. If you are adding your own functions to the library, put the code for them in this file.
4. Compile and link your DLL files. Use the /Ge- option to create a DLL and the /Rn option to create a subsystem. For example:
   `icc /Ge- /Rn mysdll.c mysdll.def
   `
5. Use the ILIB utility to add the object modules that contain the initialization and termination functions to your import library. These objects are needed by all executable modules and DLLs, and are contained in CPPRNO36.LIB for subsystem programs.

   Note: If you do not use the ILIB utility, you must ensure that all objects that access your runtime DLL are statically linked to the appropriate object library.

6. Compile your executable modules and other DLLs with the /Gn+ option to exclude the default library information. For example:

           icc  /C /Gn+ /Ge+ /Rn myprog.c

           icc  /C /Gn+ /Ge- /Rn mydll.c

   When you link your objects, specify your own import library.

   If you are using or plan to use the API, specify KERNEL32.LIB. For example:

          ILINK myprog.obj mysdlli.lib KERNEL32.LIB

          ILINK mydll.obj mysdlli.lib KERNEL32.LIB /DEF mydll.exp

   To compile and link in one step, use the commands:

           icc  /Gn+ /Ge+ /Rn myprog.c mysdlli.exp KERNEL32.LIB

           icc  /Gn+ /Ge- /Rn mydll.c mysdlli.exp KERNEL32.LIB

   If you are using or plan to use the API, specify OS2386.LIB. For example:

       	ILINK myprog.obj mysdlli.lib OS2386.LIB

          ILINK mydll.obj mysdlli.lib OS2386.LIB /DEF

   To compile and link in one step, use the commands:

           icc  /Gn+ /Ge+ /Rn myprog.c mysdlli.exp OS2386.LIB

           icc  /Gn+ /Ge- /Rn mydll.c OS2386.LIB

7. If you did not use the ILIB utility to add the initialization and termination objects to your import library, when you link your modules, specify:
   1. CPPRNO36.LIB
   2. Your import library
   3. The linker option /NOD.

   For example:

       ILINK /NOD mydll.obj CPPRNO36.LIB mysdlli.lib KERNEL32.LIB /DLL mydll.exp;

   The /NOD option tells the linker to disregard the default libraries specified in the object files and use only the libraries given on the command line. If you are using icc to invoke the linker, the commands would be:

>      icc  /B /NOD /Rn myprog.c CPPRNO36.LIB mysdlli.lib

>      icc  /Ge- /B /NOD /Rn mydll.c CPPRNO36.LIB mysdlli.lib

> The linker then links the objects from the object library directly into your executable module or DLL.

Subsystem Libraries

Example of a Subsystem _DLL_InitTerm Function (OS/2)