当前位置:网站首页>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.
边栏推荐
- 八、抽象类的接口的区别
- Gradle插件与代理服务器导致Sync Project失败的问题
- Convolutional Nerual Nertwork(CNN)
- 自监督论文阅读笔记 S3Net:Self-supervised Self-ensembling Network for Semi-supervised RGB-D Salient Object Det
- opencv
- 自监督论文阅读笔记FIAD net: a Fast SAR ship detection network based on feature integration attention and self
- 进程间通讯 (IPC 技术) - 信号
- 设备树(devicetree)-dts语法
- Qemu 搭建Armv8 平台
- page fault-页异常流程
猜你喜欢
随机推荐
Practice of MySql's Sql statement (try how many you can write)
cmdline -[command line,__fdt_pointer,initial_boot_params] boot_command_line 获取
MATLAB给多组条形图添加误差棒
八、抽象类的接口的区别
ZEMAX | 在OpticStudio中建立扩增实境(VR)头戴式显示器
PCB设计经验之模拟电路和数字电路区别为何那么大
Makefile
优雅的拦截TabLayout的点击事件
c#,.net 下载文件 设置断点
自监督论文阅读笔记 Self-Supervised Deep Learning for Vehicle Detection in High-Resolution Satellite Imagery
自监督论文阅读笔记Reading and Writing: Discriminative and Generative Modelingfor Self-Supervised Text Recogn
设备树解析源码分析<devicetree>-1.基础结构
东南亚跨境电商
A.1#【内存管理】——1.1.3 page: struct page
三分钟看懂二极管的所有基础知识点
交叉熵(第六周)
IO 复用
布尔盲注需简化代码
window下VS2022封装动态库以及调用动态库
自监督论文阅读笔记 Ship Detection in Sentinel 2 Multi-Spectral Images with Self-Supervised Learning









