当前位置:网站首页>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.
边栏推荐
猜你喜欢
随机推荐
设备树(devicetree)-dts语法
VSCODE 常见问题
观看华为AI技术领域课程--深度学习前三章总结
ASP.NET MVC3的伪静态实现
STM32启动文件的选择
五、int和Integer有什么区别?
php连接数据库脚本
ASP.NET MVC:自定义 Route
window下VS2022封装静态库以及调用静态库
最优化方法概述
Typora
AI智能剪辑,仅需2秒一键提取精彩片段
常见的电容器有哪些?唯样商城
在大程序中怎么样显示LED点阵
Android学习 | 08.SQLiteOpenHelper
classpath:与classpath*的比较
C# Base64加密
SolidWorks 操作视频 | 隐藏高手必备工具Defeature,让设计隐藏更彻底
Mysql 外键详解(Foreign Key)
ucos任务调度原理