Solved

What is .LIB/.DEF

Posted on 1997-05-16
1
1,835 Views
Last Modified: 2010-02-09
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
Comment
Question by:ahler
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 

Accepted Solution

by:
Shrif earned 50 total points
ID: 1163434
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question