当前位置:网站首页>VS2022 encapsulates static libraries and calls static libraries under window
VS2022 encapsulates static libraries and calls static libraries under window
2022-08-03 06:10:00 【Shiyu】
First, create a new project MyLib (encapsulate your own static library)
1. Header file Test.h: (_declspec(dllexport) should be placed in front of the exported class name, indicating that the package should be exported to the library)
#pragma onceclass _declspec(dllexport) Test{public:void say();};
2. Source file Test.cpp:
#include "Test.h"#includevoid Test::say() {std::cout << "Hello! My name is linyu!" << std::endl;}
3. Right-click project properties -> configuration properties -> configuration type (modified to static library.lib):
4. Right-click to generate, a static library will be generated
Second, create a new project TestMyLib (calling the library just encapsulated)
1. Copy the header file Test.h to the source file directory of the project
2. Go back to the project, header file -> right click -> add existing item Test.h
3. Linker->General->Additional library directory, link to the directory where MyLib.lib is located:
4. Linker->Input->Additional dependencies, add the generated library name MyLib.lib
5. Write TestMyLib.cpp file:
#include #include "Test.h"int main(){Test t;t.say();}
6. Click to run
The reason for this problem is that the current project is the Debug version, and the referenced library file is the Release version.
Solution 1: Just change the current Debug mode to Release mode.
Solution 2: Regenerate a debug version of the library file.Then modify the linker--general--additional library directories.Re-include the directory where the debug repository is located.
边栏推荐
猜你喜欢
随机推荐
SolidWorks 操作视频 | 流体分析结果演示
MySql的Sql语句的练习(试试你能写出来几道呢)
【DC-5 Range Penetration】
【第二周】卷积神经网络
自监督论文阅读笔记 Self-supervised Label Augmentation via Input Transformations
梯度下降、反向传播
深度学习理论课程第四、五章总结
电子元器件之电子变压器可分为哪几类?
Typora
进程间通信IPC - 信号量
ZEMAX | 探究 OpticStudio 偏振分析功能
C# 数组之回溯法
滚动条 scrollbar 和scrollbar-thumb 样式
ZEMAX | 如何创建简单的非序列系统
自监督论文阅读笔记 Self-Supervised Visual Representation Learning with Semantic Grouping
MCU接收串口字符型数据转换成数据型数据
Phase Vocoder的补充完善,Matlab音频变速不变调、变调不变速
ZEMAX | 如何使用渐晕系数
自监督论文阅读笔记 Self-supervised Learning in Remote Sensing: A Review
What is parametric design, let's understand it through practical operation?| SOLIDWORKS How-To Videos