.lib vs .dll

Started by
3 comments, last by force_of_will 15 years, 11 months ago
What exactly is the difference from packaging a set of code in a .lib or .dll? From what i read advantage of using .dll is that if 2 packages are using that same .dll there is only 1 instance used where with a lib each .dll and .exe has it own copy. Dis advantage of .dll is that it does not allow you to use templates as any parameters or return values be is can get thing messed up. From this I can't think any reason not to use a .lib file unless it is huge and I don't want to have multiple version being created since i think the use of template are very useful and would want to be able to use them if i needed. Have i missed anything?
Advertisement
dlls let you link dynamically, meaning you can load them during execution of your program. static libraries are linked during the linking stage, and you can't change them without recompiling/linking everything.
well i guess i will try to do as much as possible without template becuase being able to update a program with just updating a dll file would be fantastic.
Quote:Original post by ibebrett
dlls let you link dynamically, meaning you can load them during execution of your program. static libraries are linked during the linking stage, and you can't change them without recompiling/linking everything.


Sort of. There is static linking and dynamic linking; then there are static libraries and dynamic libraries.

Static linking means that the functions that are used from the library are directly incorporated into the compiled binary.

Dynamic linking means that you rely on a separate library to be available at runtime, and the routines you use are not directly incorporated into the binary. This helps reduce the size of the binary, and redundant code doesn't consume more disk space.

Static libraries are loaded in memory whenever an executable that uses them is loaded. If you load five programs that use a library, that library will be loaded five times.

Dynamic (shared) libraries help reduce the memory footprint. They are loaded when the first binary to use them is loaded (or perhaps before). If you load five programs that use a library, that library will be loaded once and used by all five programs.

There are pros and cons to each model. For instance, static linking mitigates dependency issues, especially useful if you make extensive use of libraries that a user is likely to already have.

We''re sorry, but you don''t have the clearance to read this post. Please exit your browser at this time. (Code 23)
You also have inside the DLL's implicit linking and explicit linking

Implicit linking means you add a .lib to your project, either in the solution space or project settings and the linker compiles the project knowing that in the startup of the exe it must load the correspondent dll


Explicit means you load it anytime in any place on your code, through the Api with functions like LoadLibrary


http://msdn.microsoft.com/en-us/library/1ez7dh12(VS.71).aspx

This topic is closed to new replies.

Advertisement