Question

Working with any C++ VS2010 solution,

  • What is a .lib for ? Why not always link a program to a library going through a DLL ?

  • Is building the program in VS2010 the only way to generate a .lib?

Was it helpful?

Solution

The .lib file that makes the link to the DLL is called an "import library", and it is indeed a static library (albeit a special kind of static library). It is just a static library that contains an amount of code to import the DLL at load-time, in other words, it acts as the "middle-man" between your code and the dynamic library.

If you create a "static library", you end up with a large .lib file which contains all the compiled code for the functions in that library. If you then create an executable using that library, all of that code is copied into the executable at link-time. This makes a larger executable, but one that doesn't depend on a separate DLL file at run-time.

If you create a "dynamic library", you end up with a large .dll file and a small .lib, as previously described. All of the compiled code for the functions in the library is in the .dll file. Now your final executable is smaller, since the code is -not- copied into the executable at link-time, but the .dll file has to be sent along with the executable, unless you can rely on it already being correctly installed on the end-user's computer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top