(Jan 14, 2010)
However, when I worked with freeglut.lib, a tool kit for OpenGL, I needed freeglut.dll during run-time, even though I planned to statically linked my project with freeglut.lib. This is opposite to what I expected, but understandable. If we do not have source code in the same solution tree, the compiler/linker does not have enough information about what should be incorporated into an executable file. Therefore, only .lib stub/proxy is employed during linking and actual implementation is found during run-time.
Another question is "So, why can't we have only .dll and throw away all .lib files when we are going to use the .dll via dynamic linking?"
Why do we need both .lib and .dll at the same time?
Today, I helped my friends figure some build and run-time problems in Visual Studio 2008. I'm not familiar with these problems at all, but I can draw some important conclusions that I earlier did not realized. It is about the usage of lib and DLL with and without source code of the library. Earlier, I created several projects and made them static libraries. Then, a few executable projects utilized them inside the same solution tree within Visual Studio 2008 development environment. These executable projects can be run without the presence of DLL at all.However, when I worked with freeglut.lib, a tool kit for OpenGL, I needed freeglut.dll during run-time, even though I planned to statically linked my project with freeglut.lib. This is opposite to what I expected, but understandable. If we do not have source code in the same solution tree, the compiler/linker does not have enough information about what should be incorporated into an executable file. Therefore, only .lib stub/proxy is employed during linking and actual implementation is found during run-time.
Another question is "So, why can't we have only .dll and throw away all .lib files when we are going to use the .dll via dynamic linking?"
A few reasons are elaborated at 'stackoverflow' website. The strongest reason may be '.lib manifest files allow us to work with different versions of DLLs in our system' and 'Native DLL's do not have strong names, so it may be possible to pick up the wrong version of the DLL'. However, it seems possible to link with only DLL by using some other work (shown in the same page of stackoverflow). The limitation of stand-alone DLL probably comes from an old design of compiler/linker/operating system (run-time platform), as it is pointed out that MS .Net can do this.