Differences between static and dynamic libraries

Source: Internet
Author: User

 

In Windows, libraries can be published in the following two ways: static Link Library and dynamic link library. Static library and dynamic library (DLL ).

 

What is static Link Library and dynamic link library)

First, both static and dynamic libraries share code.

If you use a static Link Library, all the definitions in lib are included in the final generated EXE, whether you wish or not.

However, if a dynamic library (DLL) is used, the dynamic library does not need to be included in the final EXE file. The dynamic library can be loaded into the address space of the application at application initialization or runtime. In addition, the dynamic library can be shared by multiple applications. Many important Libraries on windows are DLL. They are shared by many applications.

Another difference between the static Link Library and the dynamic library (DLL) is that the static Link Library cannot contain other dynamic link libraries or static libraries, other dynamic or static link libraries can be included in the dynamic link library.

 

The differences between static and dynamic link libraries in development and usage:

The file format after static Link Library compilation is *. Lib.

Therefore, you only need the library developer to provide the. h header file and. Lib file of the library.

 

When developing a static library, you only need to declare the function or class in the header file, and then implement the function or class in the file.

When used, add the. h header file to the project, and then specify the. Lib file to be linked.

You can use # pragma comment (Lib, "libfilepath") to specify the static library to be linked. Or set it in project-> dependency.

 

For dynamic link library (DLL ):

The use of the Dynamic Link Library requires the developers of the library to provide the generated. Lib file and. dll file (the DLL is used implicitly, and the link during compilation ). Alternatively, you can only provide DLL files (using loadlibrary to explicitly use DLL files, which is loaded during runtime ).

DLL development and use require the declaration of export and import. For dynamic link libraries, it is recommended that you take a look at windows via C ++ (Windows core programming language translated in Chinese ). The book is very clear and thorough.

 

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.