Library: One Word, Many Meanings

Part of the confusion surrounding dynamic link libraries results from the appearance of the word library in several different contexts. Besides dynamic link libraries, we'll also be talking about ”object libraries“ and ”import libraries.“

An object library is a file with the extension .LIB containing code that is added to your program's .EXE file when you run the linker during static linking. For example, the normal Microsoft C object library that you link with small-model Windows programs is SLIBCEW.LIB.

An import library is a special form of an object library file. Like object libraries, import libraries have the extension .LIB and are used by the linker to resolve function calls in your source code. However, import libraries contain no code. Instead, they provide LINK with information necessary to set up relocation tables within the .EXE file for dynamic linking. The LIBW.LIB and WIN87EM.LIB files included with the Windows Software Development Kit are import libraries for Windows functions. If you call Rectangle in a program, LIBW.LIB tells LINK that this function is in the GDI.EXE library and has an ”ordinal number“ of 27. This information goes into the .EXE file so that Windows can perform dynamic linking with the GDI.EXE dynamic link library when your program is executed.

Object libraries and import libraries are used only during program development. Dynamic link libraries are used during run time. A dynamic library must be present on the disk when a program is run that uses the library. When Windows needs to load a dynamic link library module before running a program that requires it, the library file must be stored in either the current directory, a directory accessible through the PATH string in the MS-DOS environment, the Windows directory, or the SYSTEM subdirectory of the Windows directory.