Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

What is .LIB/.DEF

Posted on 1997-05-16
1
Medium Priority
?
1,857 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
1 Comment
 

Accepted Solution

by:
Shrif earned 200 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
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.
Suggested Courses

885 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