Static compilation dynamic compilation; static link dynamic link; static library and dynamic library

Source: Internet
Author: User

Static Compilation: compile all the DLL and masterProgramAll are compiled into a main program.
Dynamic Compilation: the compilation result is that the main program is the main program, and each module is each module.
Static compilation and dynamic compilation can be used to set dynamic settings of project properties!
Static link: the static link has written the functions in the library into the executable file. That is, the static link puts the required library functions into your exe. Therefore, static compilation must be implemented through static links.
Dynamic Link: the dynamic link only writes the positioning information of the function in the database to the executable file, and then dynamically links the DLL according to the positioning information during running. Therefore, dynamic compilation must be implemented through dynamic links.

Static Library: the static library will be connected to the target during program compilation. Code . So the program to be statically loaded, that is, the static library, is a file with the Lib suffix (in Windows ). You can create a Win32 project in vs2005 and select static library. After compilation, A. Lib file is generated (for example, my. Lib is generated ). Then how can we reference this static library?
A. There are two methods to add a static library to the project:
Method 1: reference. Lib in Project Settings, and Add. Lib in project-setting-link-Object/library modules. (You must set the correct reference path in tools/options)

Method 2: Add Lib, project-add to project-files in the project, and select the correct. Lib.
B. Include. H files in the project; (may need to be correctly set in tools/options?
C. Use functions in the static library in the project;
Dynamic library: the dynamic library is not connected to the target code during program compilation, but is loaded only when the program is running. Therefore, the dynamic library is required when the program is running. So the program to be dynamically loaded, that is, the dynamic library. Generally, when a dynamic library is generated, there will be two files, one imported to the Lib file and the other DLL. Import to database is used for dynamic compilation of the main program, and DLL is used for dynamic loading when the main program is running.
Differences between static libraries and import/export libraries (though both lib files ):
They are actually different things. 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.
The dynamic library can be called in two ways:
A: Display link: similar to the use of static libraries, there are three steps: reference. Lib, including header files, using the export function. DLL error, the main process crashes.
B: implicit link: directly use loadlibrary to load the required dynamic library, and then specify the required export function, with the highest efficiency! It is usually used in the configuration file to configure which DLL to load. If a DLL error occurs, the main process will not crash.
Typedef uint (callback * lpfndllfunc1) (DWORD, uint );
Hinstance hdll; // handle to DLL
Lpfndllfunc1 lpfndllfunc1; // function pointer
Hdll = loadlibrary ("mydll ");
If (hdll! = NULL)
{
Lpfndllfunc1 = (lpfndllfunc1) getprocaddress (hdll,
"Dllfunc1 ");
}
Freelibrary (hdll );
Implicit links are sometimes called dynamic links during static loading or loading. Explicit links are sometimes called dynamic links during loading or running.
Static libraries can only be statically linked, while dynamic libraries can also be statically linked. There are two types of dynamic links. That is, dynamic links during loading and dynamic links during runtime.

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.