问题如下:

建立dll项目后,在Api_Head.hpp头文件中,定义宏:

#ifndef API_HEAD_HPP
#define API_HEAD_HPP

#ifdef API_DLL_COMPILATION
#define API_IMPORT_EXPORT __declspec(dllexport)
#else
#define API_IMPORT_EXPORT __declspec(dllimport)
#endif

class API_IMPORT_EXPORT CServerControl  {
public: 
    static void init();
    int fun();

private:
    static std::map<const uint8_t, std::shared_ptr<IHelp>> mControl;
    static std::mutex mControlMutx;
};

#endif

Api_Head.cpp中的定义如下:

#define API_DLL_COMPILATION(很重要)

#include “Api_Head.hpp”

    std::map<const uint8_t, std::shared_ptr<IHelp>> mControl;
    std::mutex mControlMutx;

在进行编译过程中mControl,与mControlMutx同时报错如下:

c++dll导入导出宏定义,出现“无法定义dllimport 实体”和“不允许dllimport 静态数据成员的定义”的问题

解决方法是在#include “Api_Head.hpp”前加上#define API_DLL_COMPILATION。

具体原因可以参考:https://docs.microsoft.com/zh-cn/cpp/cpp/using-dllimport-and-dllexport-in-cpp-classes?view=vs-2019

c++dll导入导出宏定义,出现“无法定义dllimport 实体”和“不允许dllimport 静态数据成员的定义”的问题

 

 

相关文章:

  • 2021-12-23
  • 2021-12-23
  • 2021-07-25
  • 2021-09-06
  • 2022-12-23
  • 2021-06-11
猜你喜欢
  • 2022-12-23
  • 2021-08-05
  • 2021-05-27
  • 2022-12-23
  • 2022-12-23
  • 2021-12-08
  • 2021-11-21
相关资源
相似解决方案