[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1859
  • Last Modified:

What is .LIB/.DEF

I'm an experienced Delphi programmer, and I've just started programming Borland C++ Builder. Right now I'm programming this C++ DLL. Then I wonder: What is a .LIB-file, what is a .DEF-file (I understand that my DLL should be shipped with these files, or???), and how do I make these files, do I have to make these files at all?

/Martin Ahler, Denmark
0
ahler
Asked:
ahler
1 Solution
 
ShrifCommented:
When you give someone your DLL file, there are two ways that they can use it in their own application.  In either case, they will be "loading" your DLL from their application.  DLL's can be loaded "implicitly" and "explicitly".  When a DLL is loaded explicitly, the user uses the Windows API calls LoadLibrary, GetProcAddress and FreeLibrary directly to: load the DLL, obtain function pointers to the DLL's functions and then free the DLL.  This is called explicit loading because the calling program must explicitly call LoadLibrary, GetProcAddress and FreeLibrary in order to use the DLL.  Implicit loading is when the DLL is loaded by the operating system on behalf of the application.  When the user launches the application, the operating system automatically knows what DLL's the application requires.  This is because the application has the list of required DLL's inside of its header's "import" list.  You can view a DLL's import list by using the DUMPBIN or TDUMP utility.  How does the import list get there?  It gets there because the application linked to the DLL's import library, which is a file that has the .LIB extension and the same name as the DLL.  As far as the linker is concerned, an .LIB is just another library.  But an "import" library is a special kind of library in that it doesn't have the actual code of the DLL but only forwarding addresses to point to the .DLL file.  The .LIB file is used so that the calling application's linker will resolve references to the functions in the DLL.  When you ship a DLL to a customer, you should also ship the DLL's import library along with your DLL.  If your customer is a C/C++ user, they will want this library so that they can link to your DLL implicitly.  The .Lib file is created automatically when link the DLL.  When the .DLL is created by your compiler, the .LIB file is created along with it.  A .DEF file, on the other hand, is not shipped with the DLL.  It is used by the author of the DLL to indicate which of the functions in the DLL are to be exported to the outside world.  A .DEF file is a handle coded text file listing those files that the DLL author wishes to export.  A .DEF file is added to a DLL project just like a source file is.  A .DEF file may also be specified on the command line to the linker.  A .DEF file is an input file to the linker.  Those functions that are exported, end up listed in the DLL header's "export" list.  You can view the exports section of a DLL by using the DUMPBIN or TDUMP utility.  Depending on how a DLL or an EXE is constructed, the DLL's or EXE's import and export lists may be viewed from Windows 95 or Windows NT's Explorer by right-clicking on the file and selecting "Quick View"

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now