Dynamic library and static library

Source: Internet
Author: User

Dynamic library and static library

Many repeated or frequently used parts are often encountered during programming. These parts are encapsulated into function libraries for ease of use and maintenance. Function libraries can be divided into static and dynamic libraries.

Static Library

  Writing is simple. Just like writing common source files, you can set the configuration type in project properties to a static library, but you must save the Library to the directory of the calling file, each time the library file is modified, it is generated and saved to the directory of the calling file.

1. Project Settings: set the project to static library type and select project properties

Set the project configuration type to static library

2. Code Writing: Compile the library file code, which is the same as writing the source file.

Library file source code

3. Generate a library file: generate the source file into a library file (*. lib). The generated library file can be seen in the Debug folder in the solution folder.

Generate library files

Open"Solution"Folder (solution folder, not project folder)

View the generated static library file in Resource Manager

4. import and use the library file:

Copy the static library file to the called project folder

Introduce the static library file and call the method in the file

5. Run the test

Call successful

PS: the source code of the database must be modified in order. Repeat steps 2 ~ Step 4

 

Dynamic library

  It is relatively complex to write and call source code. Before defining a function, add "_ declspec (dllexport)". Set the configuration type in the project attribute to a dynamic library, you do not need to save the database to the directory of the calling file. Therefore, you do not need to save each modification to the calling file directory.

1. Project Settings: set the project to a dynamic library type

Select Project Properties

Set the project configuration type to dynamic library

2. Code Writing: Compile the library file code, which is the same as writing the source file, but add "_ declspec (dllexport)" before function definition )"

Library file source code

3. Generate a library file: generate the source file into a library file (*. dll). The generated library file can be seen in the Debug folder in the solution folder.

Generate library files

Open"Solution"Folder (solution folder, not project folder)

View the generated static library file in Resource Manager

4. import and use the library file:

Introduce the dynamic library file and call the method in the file

5. Run the test:

Call successful

 

It can be seen that the dynamic library is suitable for sharing. Multiple projects can share one dynamic library to reduce the program volume. Static libraries are suitable for private and projects do not share static libraries.

Related Article

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.