Solved

What is .LIB/.DEF

Posted on 1997-05-16
1
1,808 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 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
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 learn how to clear a vector as well as how to detect empty vectors in C++.

747 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now