当前位置:网站首页>Use of static library and dynamic library
Use of static library and dynamic library
2022-06-26 02:03:00 【_ Bruce】
First, let's introduce the static library ( Static link library )、 Dynamic library ( Dynamic link library ) The concept of , First of all, both are ways of code sharing .
Static library : In the link step , The connector will get the required code from the library file , Copy to the generated executable file , This library is called a static library , Its characteristic is that the executable file contains a complete copy of the library code ; The disadvantage is that if it is used many times, there will be multiple redundant copies . That is, all the instructions in the static library are directly included in the final generated EXE It's in the document . stay vs Create a new project to generate a static library in , After successful compilation and generation , Only one .lib file
Dynamic library : Dynamic link library is a library that contains code and data that can be used by multiple programs at the same time ,DLL It's not an executable file . Dynamic linking provides a way , Enables a process to call functions that are not part of its executable code . The executable code of the function is in a DLL in , The DLL Contains one or more compiled 、 Functions linked and stored separately from the processes that use them . stay vs Create a new project to generate dynamic library in , After successful compilation , Produce a .lib Documents and a .dll file , Creating a dynamic library requires
__declspec(dllexport) As a prefix to a function :__declspec(dllexport) void test1();
Then the static library and the dynamic library lib What's the difference ?
In a static library lib: The LIB Contains the function code itself ( That is, including the index of the function , It also includes the implementation of ), Add code directly to the program at compile time
In dynamic library lib: The LIB Contains the... Where the function is located DLL File and function location information in the file ( Indexes ), The function implementation code is loaded in the process space by the runtime DLL Provide
All in all ,lib It's used when compiling ,dll It's used at runtime . If you want to compile the source code , It only needs lib; If you want to make the dynamic link program run , It only needs dll.
Call dynamic library : Implicit linking
Implicit linking need .h file ,dll file ,lib file
(1) take dll Put it into the working directory of the project
(2) Set item properties --vc++ Catalog -- The library directory is lib Path
(3) take lib Add to project properties -- The linker -- Input -- Additional dependency ( Or add... Directly to the source code #pragma comment(lib, “**.lib”))
(4) Add... To the source file .h The header file
Then call ordinary functions as usual 、 class 、 Variable
Use static libraries
need .h file ,lib file
(1) Set item properties --vc++ Catalog -- The library directory is lib Path
(2) take lib Add to project properties -- The linker -- Input -- Additional dependency ( Or add... Directly to the source code #pragma comment(lib, “**.lib”))
(3) Add... To the source file .h The header file
边栏推荐
猜你喜欢

Pointnet/Pointnet++学习

-- EGFR FISH probe solution

biggan:large scale gan training for high fidelity natural image synthesis

Abnova CSV monoclonal antibody solution

初识Opengl

Energetic girl wangyujie was invited to be the spokesperson for the global finals of the sixth season perfect children's model

Pixel6 unlock bootloader

Differences and functions of TOS cos DSCP

One minute to understand the difference between synchronous, asynchronous, blocking and non blocking

【js】免费api判断节假日、工作日和周六日
随机推荐
PTA class a simulated third bomb: 1140-1143
vtk初始化代码学习1
Easyexcel read file
jenkins汉化及汉化无效解决方案
Gun make (7) execute make
高手常用的电脑快捷键
Redis的使用
缓存技术之第一次亲密接触
SDRAM控制器——添加读写FIFO
How to efficiently complete daily tasks?
PTA class a simulated second bullet: 1136-1139
初识Opengl
记录一个诡异的图片上传问题
其他代码,,vt,,,k
求n乘阶之和
影响个人成长的三个因素
Principle of voice wake-up
NDK20b FFmpeg4.2.2 编译和集成
元气少女王钰洁 受邀担任第六季完美童模全球总决赛代言人
CS144 环境配置