1使用MSVC封装库文件
1.1配置
.h文件需要配置,导入导出以及平台设置
#ifdef CLASS_LIBRAR
#define CLASS_EXPORT __declspec(dllexport)
#else
#define CLASS_EXPORT __declspec(dllimport)
#endif
.h文件配置
#ifdef __cplusplus
extern "C" { //only need to export C interface if used by C++ source code
#endif
__declspec(dllimport) void MyCFunc();
__declspec(dllimport) void AnotherCFunc();
#ifdef __cplusplus
}
#endif
.cpp文件函数正常编写
2在Visual Studio 2022中成功封装并调用库的案例
2.1 封装教程
第一步 创建动态库项目
创建新项目——》选择动态库模板
第二步 删除自带文件
创建成功后,删除自带的头文件和源文件
第三步 配置属性
选中项