【问题标题】:Unresolved external symbol - LNK2019 from C++ dll未解析的外部符号 - 来自 C++ dll 的 LNK2019
【发布时间】:2011-12-30 14:25:42
【问题描述】:

我使用 GetProcAddress 从 C++ dll 将 GetInstance 函数加载到我的基本代码并获取 一些未解决的外部符号错误:

错误LNK2019:无法解析的外部符号“_declspec(dllimport) 公共:无符号整数 _th​​iscall RegTestAPI::CTestmode_Sle70::SetMSfr(unsigned int,unsigned short,char *)" (_imp?SetMSfr@CTestmode_Sle70@RegTestAPI@@QAEIIGPAD@Z) 在函数 "int __cdecl SetUserDescriptor(unsigned char,unsigned int,unsigned int)" (?SetUserDescriptor@@YAHEII@Z)

DLL 代码

标题

extern "C" _declspec(dllexport) CTestmode* GetInstance();

来源

CTestmode *cTestmode;

extern "C" _declspec(dllexport) CTestmode* GetInstance()
{
    cTestmode = CTestmode::Instance();

    return cTestmode;
}

...

// in header
static CTestmode* Instance();
... 
static CTestmode* m_pInstance;

// in source
CTestmode* CTestmode::Instance()
{
    if(m_pInstance == NULL)
    {   
        m_pInstance = new CTestmode();
    }

    return m_pInstance;
}

工具代码

typedef CTestmode* (*CTestModeInstance)(void);

CTestmode *pMyTM;

...

HMODULE handleTestmode;
handleTestmode = LoadLibrary("Testmode.dll");

CTestModeInstance cTestModeInstance = (CTestModeInstance)GetProcAddress(handleTestmode, "GetInstance");

pMyTM = (cTestModeInstance)();

我的想法是调用约定有问题(查看错误消息 -> __thiscall 和 __cdecl 提示:两个项目都设置为 __cdecl (/Gd))?!

任何想法为什么这不起作用?

提前谢谢你!

问候

【问题讨论】:

  • 我们需要SetUserDescriptor的代码,以及CTestmode_Sle70::SetMSfr的声明和定义,而不是所有发布的代码。

标签: c++ dll calling-convention unresolved-external


【解决方案1】:

错误信息不易阅读,但不言自明。函数CTestmode_Sle70::SetMSfr 在函数SetUserDescriptor 中被引用,但它没有在任何地方定义。链接器无法绑定对SetMSfr 的调用,因为该函数不存在。

【讨论】:

    【解决方案2】:

    您缺少SetMSfr(unsigned int,unsigned short,char *); 的实现

    【讨论】:

      猜你喜欢
      • 2012-12-17
      • 1970-01-01
      • 2015-08-26
      • 2014-11-07
      • 2013-06-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-04
      • 1970-01-01
      相关资源
      最近更新 更多