Sign in to follow this  
3dmodelerguy

.lib vs .dll

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this