Share via


The .lib and .dll files

Question

Thursday, April 9, 2009 2:55 PM

Hi,

I want to know that ,to use a dll , is it mandatory to have it's .lib file and header file.
It is obvious that header file contains declaration then what .lib contains then? and what role a .def file plays apart from .lib?
What I understand that, static library is get inserted into an .exe and dynamic library is loaded at run time and we can unload after completing it's task.

thanks

All replies (9)

Thursday, April 9, 2009 3:24 PM ✅Answered | 2 votes

Quote>what .lib contains then?

A lib file associated with a DLL is an import library file.
It contains the entry point information into the DLL for
its exports so the linker can resolve references in the
program using the DLL.

Quote>what role a .def file plays apart from .lib?

Read this:

How to write DLLs using Visual C++
http://www.geocities.com/sujitmanolikar/dllhowto.html?20095

  • Wayne

Thursday, April 9, 2009 3:46 PM ✅Answered | 1 vote

Just to answer your questions as it is apart from the questions answered by wayne:
**
Ques #1: Is it mandatory to have .lib file and header file?
**.lib is not mandatory if you are linking to dll explicitly (dynamic linking). It is needed only for static - linking.

**Ques #2: What role a .def file plays apart from .lib?
**if you are not declaring functions with  __declspec(dllexport) then .DEF is need for Dll.
for more information : http://msdn.microsoft.com/en-us/library/aa278947(VS.60).aspx

Also verify this link to know more about what is a dll http://support.microsoft.com/default.aspx/kb/815065.

  • Anand

Friday, April 10, 2009 7:04 AM ✅Answered | 1 vote

The output of compiling a C or C++ file is an object file (.obj). Many years before Windows, all executables were created by linking object files together; that is called static linking. Compilers and operating systems (before Windows) began implementing dynamic linking in which object files could be used that remained separate from applications that used them. In DOS (remember that?) object files could be gathered together in a library; a .lib file. DOS did not have dynamic linking and object files in a library were always linked statically. Windows (as you know) supports dynamic linking and the linker uses a lib file to get information about the functions linked to, whether statically or dynamically. I have a little bit more in my Compiling and Linking and my Static versus Dynamic Linking.Sam Hobbs; see my SimpleSamples.Info


Friday, April 10, 2009 7:09 AM | 1 vote

.lib is not mandatory if you are linking to dll explicitly (dynamic linking). It is needed only for static - linking.

The term "static - linking" in reference to DLLs is contradictory and can be very confusing. It is common and much more meaningful to call it implicit linking.Sam Hobbs; see my SimpleSamples.Info


Wednesday, April 15, 2009 7:47 AM

thanks


Wednesday, April 15, 2009 7:48 AM

thanks Anand.


Wednesday, April 15, 2009 7:48 AM

thanks a lot  WayneAKing


Wednesday, December 4, 2013 8:36 AM

I am using run time dynamic linking and i have configured the project(VS2010) to produce a .dll. I can see that it produces a .lib file too. Please explain this behavior? Is there any configuration setting to stop VS from creating the .lib file?


Wednesday, December 4, 2013 11:28 PM

I am using run time dynamic linking and i have configured the project(VS2010) to produce a .dll. I can see that it produces a .lib file too. Please explain this behavior? Is there any configuration setting to stop VS from creating the .lib file?

In order to use the DLL, the client code needs to link to the associated LIB file, which describes the entry points of the DLL.

There is no good reason NOT to generate the LIB file if generating the  DLL file. Or can you think of a reason?

By the way, in future, rather than dredging up a thread that is years old, and already answered, post your question in a new thread.