Previous Next Up Title Contents Top Library

3.9.3. BUILDING DLLS

The following example illustrates how to create the import and export libraries for a DLL. The import library is linked with the application that uses this DLL. The export library is linked with the DLL. The export library is not explicitly listed in the command because the linker automatically generates it along with the import library.

#Generate import library (.lib) and export library (.exp)

#from a module-definition (.def) file for a DLL

$(TARGET).lib $(TARGET).exp: $(TARGET).def

$(IMPLIB) /out:$(TARGET).lib /machine:$(MACHINE) /def:$(TARGET).def

The following example links the DLL. The /DLL and /ENTRY options are required to build a DLL.

The /DLL option specifies that the output file is a DLL. The /ENTRY option specifies the name of the DLL initialisation routine.

#Build DLL using objects and export library

$(TARGET).dll: $(OBJS) $(TARGET).exp

$(LINK) @<<

/out:$(TARGET).dll

/dll

/entry:$(DLLINIT)

/debug:full

/debugtype:cv

/machine:i386

/subsystem:windows

$(LINK_FLAGS)

$(OBJS)

$(TARGET).exp

$(LIBS)

<<

The NTWIN32.MAK file supplied in \MSTOOLS\H or \MSVC20\INCLUDE will help simplify the build process. Many of the compiler and linker switches shown in the above examples are defined as macros in this file.


Previous Next Up Title Contents Top Library