If I make a dll file and use it in a program, I have to have the dll for the program to run. If I make a .lib file, how does that work? Is it compiled into the exe or what?
Printable View
If I make a dll file and use it in a program, I have to have the dll for the program to run. If I make a .lib file, how does that work? Is it compiled into the exe or what?
I think the DLL is used for dynamic linking, whereas the LIB is used for static linking.
Megatron is correct - and adding just a bit
When you link to a reference in a .lib file, you don't necessarily suck the whole .lib file into your .exe. When you have a reference to a .dll, on the other hand, you have to have the whole .dll on any system that runs your code.
The idea behind a .lib file is to make a piece of code you put on any system, with no worries abour portability. The idea behind a dll is to make a small executable, and you do have to watch movinf it from system to system.
but a dll can be shared, so different programs that use the same dll can use the same copy (even in memory), whereas libs are there as many times the programs are there. This can be a waste of memory and explains why windows is based on dll - imagine every started app needs to have it's own copy of gdi32.dll, kernel32.dll and user32.dll in memory, maybe even kernel.exe, user.exe and gdi.exe (the 16-bit versions).
and the lib is compiled into the exe, yes
When DLL's are created they are linked against any libraries required... kinda like an executable file. Whereas, static libraries are not. They are more like object code (.obj files).
DLL's can also have resources compiled into them (eg. icons, bitmaps, menus, dialog templates, ect. ).