Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How are Header file (.h), Library file (.lib) and DLL (.dll) files related

I have seen in driver libraries these three files. How are the three files related, what is the order in which the files are compiled and what is the content of each file? In addition to this I have also seen .a files are they same as .lib?

like image 253
gpuguy Avatar asked May 19 '13 18:05

gpuguy


People also ask

What is .LIB and .DLL file?

LIB is a static library where functions and procedures can be placed and called as the application is being compiled. A DLL or Dynamic Link Library does the same function but is dynamic in a sense that the application can call these libraries during run-time and not during the compilation.

What is difference between DLL and header file?

H Declares the interface to a library - including functions, structures, and constants. Written in the C language. LIB Either declares the binary interface to a dynamic library (DLL) or contains the binary code of a library.

Is header file and library file same?

No. Header File is the file where all the headers name are mentioned that going to be used or consumed in the main code file. On other hand Library is the file where the implementation code of each header is written down which is mentioned in the Header file.


1 Answers

.lib and .dll files are both containers of executables of a Windows library (.o or .obj files), with the former (.lib) containing stuff (functions, definitions, etc) that you have to link statically to the executable file of your project. The latter (.dll) is either already present in your system or you put it into your system, and it is dynamically linked to the executable file of your project.

For Unix/Linux systems, the file-extensions are .a and .so respectively (that is, .a instead of .lib, and .so instead of .dll).

In all cases, when compiling your project you must #include one or more of the .h files provided to you by the library you are using (they are called header files), because that's where the stuff inside the executables of the library get defined.

EDIT

The main advantage of a statically linked library is that it is self-contained (no external dependencies) but it increases the size of your own executable file. The main disadvantage is that future versions must be re-compiled and re-distributed.

For dynamically linked libraries, we re-distribute just the updated library executables. The main disadvantage is that our program relies on the library being already installed on the customer's system.

like image 100
Harry K. Avatar answered Sep 27 '22 23:09

Harry K.