Basic knowledge of C + + dynamic link library and static link library

Source: Internet
Author: User

  1. Dynamic Link Library

    1. Dll:dynamic-link Library
    2. is a non-executable binary program file that contains functions that are called by executable programs and other DLLs.
    3. The most important DLLs in Windows:
      1. Kernel32.dll: Manages memory, processes, threads.
      2. User32.dll: Perform user interface tasks such as window creation and message delivery.
      3. GDI32.dll: Drawing and displaying text.
    4. DLLs are not unique extensions, such as Linux, which are often. So.
    5. Use:
      1. File 1:.lib Required: Note Not a static library that contains the function and variable symbol names exported by the DLL.
      2. Requires file 2:dll file: Actual functions and data.
      3. When compiling a linked executable, you only need to link to the inbound file, and the code and data are not copied to the executable file (you can compare static links).
      4. Loads the required DLL files while the program is running.
    6. Release Product: Executable file +dll
    7. Advantages
      1. Written in multiple languages, and used.
      2. Scalability: Update DLL when product is updated
      3. Two times development, developers can invoke functions in the DLL, such as OpenCV.
      4. Save disk space and memory.
      5. Facilitates resource sharing: resources such as strings, icons, bitmaps, and multiple programs can use DLLs to share these resources.
      6. It is suitable for large-scale software development, makes the development process independent, the coupling degree is small, facilitates the development and the test between different developers and the development organization.
    8. DLL loading:

      1. Implicit linking: Use LIB to import the project, linker attach dependency.
      2. Explicit links: Using LoadLibrary is the display link,
    9. DLL Hell (DLL Hell):

      1. Adding member variables, modifying the base class of the exported class, virtual functions, and so on, can be caused.
      2. One component of an application may be overwritten by an incompatible component of another application.
  2. Static link library

    1. Lib:static link library, the suffix is usually the static link lib,linux under the *.a file, which corresponds to the dynamic link library. So
    2. Use: A static library is a package of one or more obj files, and if the static library is wrong, the corresponding obj is wrong.
    3. Release Product: Executable program
    4. Advantages:

      1. Code load execution is fast.
      2. Avoid DLL Hell.
    5. Load mode:

      1. #pragma comment (lib, "LibTest.lib");
      2. Settings in the IDE
  3. Contrast
    1. Both the static link library and the dynamic link library are the ways to share the code.
    2. Using a static link library, the instructions in Lib are included directly in the resulting EXE file.
    3. If a DLL is used, the DLL does not have to be included in the final EXE file, and the exe file can be "dynamically" referenced and unloaded with the EXE independent DLL file.

Basic knowledge of C + + dynamic link library and static link library

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.