DLL = Dynamic Link Library
it contains compiled machine code for functions, classes, etc., but not in a form the linker can use directly.
DLLs are loaded at runtime (when your program starts, or later if you load them manually).
if the DLL is missing at runtime, you get errors like
The program can't start because *.dll is missing...
There are two types of .lib files in Visual Studio:
(a) Static Library (.lib)
- Contains all compiled code directly
- Gets copied into your .exe during linking
- No DLL is needed at runtime--the code is inside your executable
(b) Import Library (.lib)
- This is the one used with DLLs
- It does not contain the code itself -- it only contains symbol information (function names, addresses) so the linker knows:
- Which functions your code will call
- That they will be found inside a specific DLL at runtime.
- At link time, you give the linker the .lib (so it knows what you're calling) and at runtime you place .dll next to your .exe (so it can actually run).
Think of the .lib as the map that tells your program "The hammer is in that toolbox over there", and the .dll as the toolbox itself.