. h header file. lib library file. dll dynamic link library file relationship

Source: Internet
Author: User

Original address: Http://blog.csdn.net/c395565746c/archive/2010/03/21/5402239.aspx

The. h header file is required at compile time, and Lib is required at the time of the link, and the DLL is required at runtime.

Additional dependencies are. Lib is not a. dll, and if a DLL is generated, a Lib file must also be generated. If you want to complete the source code compile and link, there is a header file and Lib is enough. If you also make a dynamically connected program run, there is enough DLL. In the development and commissioning phase, of course, it is best to have.

The relationship of the. h. lib. dll is:

h file function is: Declare Function interface

DLL file function is: function executable code

When we refer to a function in an H file in our own program, how does the linker know which DLL file to call? This is what lib files do: Tell the linker which DLL the function is calling, where the function executes the code in the DLL , This is why additional dependencies are required. LIB file, it acts as a bridge. If you generate a static library file, there is no DLL, only Lib, and then the function executable code part is also in the Lib file

There are two kinds of libraries with Lib suffix, one is static link library (static libary, hereinafter referred to as "still Library"), and the other is the import library (import libary, hereinafter referred to as "import library") of Dynamic Connection library (DLL, hereinafter referred to as "Dynamic Library"). A static library is a package of one or more obj files , so some people simply refer to the process of generating lib from the obj file as archive, which is merged together. For example, if you link a static library, if there is a mistake, it will find out exactly which obj is wrong, that is, static Lib is just a shell. The dynamic library usually has the corresponding import library, the convenience program statically loads the dynamic link library , otherwise you may need oneself loadlibary the DLL file, then GetProcAddress obtains the corresponding function manually. With the import library, you only need to link to the import library and follow the declaration of the header file function interface to call the function. The difference between an import library and a static library is that they are essentially different things. The static library itself contains the actual execution code, symbol table and so on, and for the import library, its actual execution code is located in the dynamic library, the import library contains only the address symbol table, etc., to ensure that the program to find some basic address information of the corresponding function.

The General Dynamic Library program has lib files and DLL files. Lib files must be connected to the application at compile time, and DLL files are not called until the run time. If there are DLL files, then the corresponding LIB file is generally some index information, specifically implemented in the DLL file. If only the Lib file, then the Lib file is statically compiled, the index and implementation are in it. A statically compiled LIB file has the advantage of not having to hang up the dynamic library when installing to the user. But there are drawbacks, that is, the application is larger, and the flexibility of the dynamic library is lost, and when the version is upgraded, a new application will be published at the same time. In the case of a dynamic library, there are two files, and one is the introduction library (. LIB) file, a DLL file that contains the name and location of the function exported by the DLL, the DLL contains the actual functions and data, the application uses the Lib file to link to the DLL file that is needed, the functions and data in the library are not copied to the executable file, Therefore, in the application's executable file, it is not the called function code, but the memory address of the function to be called in the DLL, so that when one or more applications run, the program code and the called function code are linked together, thus saving memory resources. As you can see from the instructions above, DLLs and. lib files must be released with the application or the application will produce an error.

both the static and shared libraries are a collection of obj files , but after a static link, there is a copy of the obj that is required to execute the program, and after dynamic linking, the executor simply contains a reference to the shared library. The shared library is equivalent to an obj file that is composed of multiple obj files, and all of its code is loaded after the link, whether needed or not.
It seems that a conclusion can be drawn:
The statically linked program is larger than the storage space used by the dynamic link, because the code copy in the library is included in the execution program;
A dynamically linked program uses more space than a static link because it loads unwanted code into the run space.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.