barry_di 2020-10-27 22:15 采纳率: 100%
浏览 308
已结题

dll导出类时,只有dll,没有.lib

动态库项目导出类,为什么只生成.dll文件不生成.lib文件

.h文件

#pragma once

#ifdef _DLL_EXPORTS
#define DLL_API  extern "C" _declspec(dllexport)
#else
#define DLL_API  extern "C" _declspec(dllimport)
#endif

DLL_API class Stu
{
public:
    Stu(int a);
    void print();

private:
    int _a;
};

.cpp文件

// DynamicLib.cpp: 定义 DLL 应用程序的导出函数。

#define _DLL_EXPORTS
#include "func.h"

#include <iostream>
using namespace std;

Stu::Stu(int a)
{
    this->_a = a;
}

void Stu::print()
{
    cout << _a << endl;
}
  • 写回答

1条回答 默认 最新

  • wlj1234 2020-10-28 15:58
    关注

    调整一下DLL_API的位置,另外在项目"属性"->"预处理器"增加_DLL_EXPORTS
    class DLL_API Stu

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?