. H header files are required for compilation, lib is required for linking, and dll is required for running.
The dependency. lib is not. dll. If DLL is generated, the LIB file is also generated. If you need to complete source code compilation and linking, it is enough to have header files and lib. If dynamic connection is also enabled, dll is enough. In the development and debugging stages, it is best to have both.
. H. lib. dll:
The role of the H file is to declare the function interface.
The role of the DLL file is: function executable code
When we reference a function in an H file in our program, how does the leader know which DLL file to call? This is the role of the LIB file: Tell the linker which DLL The called function is in and where the function Execution Code is in the DLL. That is why dependencies need to be attached. LIB file, which serves as a bridge. If a static library file is generated, there is no DLL and only lib. the executable code of the function is also in the lib file.
Currently, there are two types of libraries with the lib Suffix: Static Libary (hereinafter referred to as "Static library") and dynamic connection library (DLL, import Libary (hereinafter referred to as "Import Database "). The static library is a package of one or more obj files, so someone simply calls the process of generating lib from the obj file Archive, that is, merging it together. For example, if you link a static library, if there is a mistake in it, it will accurately find which obj is wrong, that is, static lib is only a shell. A dynamic library usually has a corresponding Import and Export library, which facilitates the program to load the dynamic link library statically. Otherwise, you may need to load the DLL file by yourself, and then manually GetProcAddress to obtain the corresponding function. With the import/export function, you only need to link the import/export function and call the function according to the declaration of the header file function interface. Import-to-database and static databases are very different. They are actually different. The static library itself contains the actual execution code, symbol table, and so on. For the import and export operations, the actual execution code is in the dynamic library, and the import and export operations only contain the address symbol table, make sure that the program finds some basic address information of the corresponding function.
Generally, dynamic library programs include lib files and dll files. The lib file must be connected to the application during the compilation period, and the dll file will be called only during the runtime. If there is a dll file, the corresponding lib file is generally some index information, the specific implementation is in the dll file. If only the lib file is available, the lib file is statically compiled and the indexes and implementations are all included. The advantage of static compiling lib files is that dynamic libraries are no longer needed during installation. However, there are also some disadvantages, that is, the application is relatively large and the flexibility of the dynamic library is lost. During version upgrade, new applications must be released at the same time. In the case of a dynamic library, there are two files, and one is imported into the database (. LIB) file. One is a DLL file. The imported file contains the name and location of the function exported by the DLL. The DLL contains the actual function and data, the application uses the LIB file to link to the required DLL file. The functions and data in the library are not copied to the executable file. Therefore, in the executable file of the application, stores not the called function code, but the memory address of the function to be called in the DLL, in this way, when one or more applications are running, the program code is linked to the called function code, thus saving memory resources. From the above description, we can see that the DLL and. LIB files must be released along with the application, otherwise the application will produce errors.
Bytes -------------------------------------------------------------------------------------
Differences between static library (Lib) and dynamic library (DLL)
Static Connection Library is to directly link the function code used in the (lib) file to the target program. Other library files are no longer needed when the program is running; dynamic Link is to link the file module (DLL) where the called function is located and the location of the called function in the file to the target program. When the program is running, find the corresponding function code from the DLL, therefore, support for the corresponding DLL files is required.
Static and dynamic libraries share code, all commands in lib are directly included in the final generated EXE file. However, if a DLL is used, the DLL does not need to be included in the final EXE file. During execution of the EXE file, the DLL file can be dynamically referenced and detached. Another difference between a static link library and a dynamic link library is that the static Link Library cannot contain any other dynamic or static Link Library, other dynamic or static link libraries can be included in the dynamic link library.
"Each lib file is defined by several functions (assuming only functions"
There are two types of lib libraries: one is to include information about the DLL file where the function is located and the location of the function in the file, known as export and warehouse; the other is to include the Function Code itself, generally the existing DLL, the former database is used; the former TC/BC in DOS is the latter one. The header file (. h) contains the function prototype declaration ).
"After the # include header file containing these function declarations, our application can use the functions in the lib file"
You also need to specify the compiler to link the corresponding library file. In the IDE environment, generally all the library files used are specified at a time, and the compiler looks for the libraries required by each module. In the command line compiling environment, the library called by each module needs to be specified.
"What is the difference between the file that directly gives the function definition, such as The. cpp file, and the header file? What is the use of the static link library"
The cpp file is the source code, and the library file is the compiled Binary Code. For example, you can call the Windows API but cannot see the same source code.
"What I still don't understand is that as long as the lib file in the static link library is used, the content of the entire lib file is put into the exe file, is it compiled or linked?"
Link lib to the target code.
From: http://www.cnblogs.com/zcshan/archive/2010/12/03/1895605.html