Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

difference between a .dll and .lib file!

Can anybody please help me in understanding the core differences between a .lib file and .dll file. how windows operating system takes care of these and co-ordinate between the two. how is this mechanism different in case of MFC and .NET environments. i know a detailed discussion might be out of scope in this forum, it would be really helpful for me if anybody has some resources or links to them. i tried to search on google, but didnt get much nice explainations. :confused:
[478 byte] By [premartha] at [2007-11-11 7:24:27]
# 1 Re: difference between a .dll and .lib file!
The OS does not 'coordinate between the two'. The OS cannot do anything with a .lib file beyond copy, delete, move, etc. You can even delete the .lib files -- once you have compiled a dll user, the dll is all you need. (that's why you dont get .libs when you buy a program, only .dll) Visual studio or other compiler and linker do the coordination! I couldnt tell you how .net does it except it certainly accepts MFC ones and visual 6.0 (and earlier) ones. I will go out on a limb here and say I doubt the protocol has changed much.

The .lib file is a file that has the stuff the linker needs to build your executable program. Windows cannot use them, but compilers and linkers can. Its a lot like a .obj file really, except it contains everything needed for all the stuff in your 'library' whereas an obj is from a single source file. It also contains a protocol for the associated .dll (basicaly, offsets of where functions start, the name and parameters(?) of the functions, calling conventions(?) and things like this).

A .dll can have a lot of different stuff -- data, functions, anything really. A dll that has shared routines is what the OS needs to run those routines -- compare this to a 'mini executable'. A program smoothly jumps from its own executable statements to the ones in the .dll and back again. Windows does some smoke and mirrors here to make the file loading efficient(ish).

Anyway, if you understand the difference between what is in a .exe and a .obj, you have a lot of the answer except for an import / export protocol and file format specifications.
jonnin at 2007-11-11 21:02:22 >
# 2 Re: difference between a .dll and .lib file!
There's an excellent book called "linkers and loaders" by Levine that explains these details in a very professional and detailed manner. I consider this book as one of my all time favorites.
I'll put it bluntly: a lib file is simply a collection of .obj files bundled together, whereas a .dll is almost like an .exe file except that it has no main() in it. So if you know the difference between .obj and .exe files, you probably know the difference between .lib and .dll files.
Danny at 2007-11-11 21:03:27 >