Windows Internals‎ > ‎FAQ‎ > ‎

Dynamic Vs Static Library

Dynamic Library
Module_1 -> Lib_1.dll [v 1_0_0_1]
Module_2 -> Lib_1.dll [v 1_0_0_4]
If Lib_1.dll [v 1_0_0_1] is loaded and dynamically shared Module_2 will have problem and vice versa.
Dynamic library is the one in which the library is only linked and during execution also it is only linked and if u are running more than one executable which uses the shared library then there will be only one copy of it in memory and all executables will only have a link to it
The dynamic library allows you to choose the function to call at run time. 

Load time might be reduced because the shared library code might already be in memory.

Run-time performance can be enhanced because the operating system is less likely to page out shared library code that is being used by several applications, or copies of an application, rather than code that is only being used by a single application. As a result, fewer page faults occur.

The routines are not statically bound to the application but are dynamically bound when the application is loaded. This permits applications to automatically inherit changes to the shared libraries, without recompiling or rebinding.

From a performance viewpoint, there is "glue code" that is required in the executable program to access the shared segment. There is a performance cost in references to shared library routines of about eight machine cycles per reference. Programs that use shared libraries are usually slower than those that use statically-linked libraries.

A more subtle effect is a reduction in "locality of reference." You may be interested in only a few of the routines in a library, and these routines may be scattered widely in the virtual address space of the library. Thus, the total number of pages you need to touch to access all of your routines is significantly higher than if these routines were all bound directly into your executable program. One impact of this situation is that, if you are the only user of these routines, you experience more page faults to get them all into real memory. In addition, because more pages are touched, there is a greater likelihood of causing an instruction translation lookaside buffer (TLB) miss.

When a program references a limited number of procedures in a library, each page of the library that contains a referenced procedure must be individually paged into real memory. If the procedures are small enough that using static linking might have linked several procedures that are in different library pages into a single page, then dynamic linking may increase paging thus decreasing performance.

Dynamically linked programs are dependent on having a compatible library. If a library is changed (for example, a new compiler release may change a library), applications might have to be reworked to be made compatible with the new version of the library. If a library is removed from the system, programs using that library will no longer work.

Static Library
The solution lies in use of static library.
Module_1 [ Lib_1.dll [v 1_0_0_1]]
Module_2 [ Lib_1.dll [v 1_0_0_4]]
The Module embedd the required dll version in itself.
Static libraries are often useful for developers if they wish to permit programmers to link to their library, but don't want to give the library source code
Static library is the one when you link that with your executable it gets bundled along with it and the excutable size will be more.
A static library requires the function to be known at compile time.