当前位置:网站首页>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.
边栏推荐
猜你喜欢

【第四周】MobileNet和HybridSN

全球一流医疗技术公司如何最大程度提高设计工作效率 | SOLIDWORKS 产品探索

Hook初探索

自监督论文阅读笔记DisCo: Remedy Self-supervised Learning on Lightweight Models with Distilled Contrastive

滚动条 scrollbar 和scrollbar-thumb 样式
深度学习理论课程第八、九、十章总结

设备树解析源码分析<devicetree>-1.基础结构

借助ginput函数在figure窗口实时读取、展示多条曲线的坐标值
深度学习理论课程第四、五章总结

三分钟看懂二极管的所有基础知识点
随机推荐
double型数据转字符串后通过MCU串口发送
三、final、finally、 finalize有什么不同?
【DC-5 Range Penetration】
关于梯度下降法的一些优化方法
SolidWorks 操作视频 | 流体分析结果演示
自我监督学习和BERT模型
【第三周】ResNet+ResNeXt
servlet学习(七)ServletContext
softmax和最大熵
什么是参数化设计,通过实操了解一下? | SOLIDWORKS 操作视频
Convolutional Nerual Nertwork(CNN)
Mysql 外键详解(Foreign Key)
自监督论文阅读笔记 TASK-RELATED SELF-SUPERVISED LEARNING FOR REMOTE SENSING IMAGE CHANGE DETECTION
6. What is the difference between Vector, ArrayList and LinkedList?(design, performance, safety)
2021-03-22
【七夕特效】 -- 满屏爱心
KASLR-内核地址空间布局随机化
AI智能剪辑,仅需2秒一键提取精彩片段
浮点型数据在内存中存储的表示
自监督论文阅读笔记 Incremental-DETR:Incremental Few-Shot Object Detection via Self-Supervised Learning