Lib file made when creating a .dll

Started by
3 comments, last by chollida1 19 years, 1 month ago
When making a .dll in visual studio a .lib file is usually created that can be used to import the objects/functions you exported into the .dll. Does anyone have more info about this .lib? Is it simply the code needed to dynamically link the .dll at runtime or does it contain the same code that the .dll does just in something that can be statically compiled?
Advertisement
It contains the code to link the library, and no functions...
If you want your exe to statically link to your dll, you'll need to include the generated lib file in your exes additional libraries.
The .lib file basicly tells the compiler where it can find the functions that are implemented in the dll. If you're using dynamic linking (LoadLibrary() and GetProcAddress()) you can just ignore the generated lib.
The .lib that is created is known as an "import library". Its job is to do all the dirty work of loading the DLL and finding and exposing the functions that you would normally do yourself through LoadLibrary and GetProcAddress. Technically it doesn't exactly use these functions (it works at load-time, not run-time), but the effect is the same. Sometimes, you're doing really strange, wacky things with plugins and patches and executable sections and whatnot and the import library won't work for you, but in almost all situations it greatly simplifies the task of using a DLL. You do not need to distribute it with your application.
Think of hte lib file as a table of contents to your dll. The DLL has the code and teh lib, often called a linker lib to differentiate it from a static lib, has the memory address, or more appropriately the offset to the method your app needs so that when you startup your app the loader can match up your external methods with the ones in teh dll.

Cheers
Chris
CheersChris

This topic is closed to new replies.

Advertisement