Subj : Re: lib files To : comp.programming From : puzzlecracker Date : Sun Oct 09 2005 09:38 am Scott McPhillips [MVP] wrote: > puzzlecracker wrote: > > Can someone provide an explanation for lib files that VS generates - I > > heard there are static and dynamic ones. How do they differ? what are > > pros and cons of each? > > > > > > Thanks > > > > A lib (for library) file contains previously compiled code, so you can > easily include it in your program and call the functions it contains. > > In the VS environment this classic definition of a lib file is a > "static" lib file. That means it actually contains the code, and when > you link it in the code becomes part of your exe file. > > A "dynamic" lib file is almost empty: It contains only stub functions > that consist of a jump to someplace else, to be defined at run time. It > satisfies the linker's need to put a function address in your exe file, > but the functions are empty. The "someplace else" that actually > contains the functions is a DLL (Dynamic Linking Library) file. Every > dynamic lib has a corresponding DLL. Windows loads the DLL when your > exe is loaded, and fixes up the jump addresses. > > Pros of DLLs: Saves memory if more than one program uses the same > functions. Only one copy needs to be loaded into memory. For example, > the operating system is largely contained in DLLs shared by all running > programs. DLLs also provide a convenient way to divide programming work > up into separate projects. Programmer A can build and test his DLL > without waiting for programmer B to fix some unrelated problem. > > Cons of DLLs: Known as "DLL Hell," there can be version management > problems. Suppose your program relies on a Microsoft DLL. Then > Microsoft updates the DLL in some incompatible way, and some other > program install brings in the new incompatible DLL file. Your program dies. > > -- > Scott McPhillips [VC++ MVP] What are prons and cons of static lib and why would you choose them as opposed to dll? Another question: when you compile a program that has a main, would lib be generated or it is only for library types? that is whether exe and lib are generated together? .