LNK2028 Managed C++ DLL calling function in another Managed C++ DLL

二次信任 提交于 2020-01-13 06:36:09

问题


I'm using VS2010 with a managed C++ DLL calling a function in another managed C++ DLL and I'm getting many LNK2028 link errors that look like this.

1>udpPkt.obj : error LNK2028: unresolved token (0A0000AA) "unsigned short __cdecl ComputeCrc16(void const *,unsigned int)" (?ComputeCrc16@@$$FYAGPBXI@Z) referenced in function "public: short __thiscall CPrivateUdpPkt::ComputeCrc(void)const " (?ComputeCrc@CPrivateUdpPkt@@$$FQBEFXZ)

When I use dumpbin /export on the called DLL I see the unresolved function listed as:

7 6 00001040 ?ComputeCrc16@@YAGPBXI@Z = ?ComputeCrc16@@YAGPBXI@Z (  unsigned short __cdecl ComputeCrc16(void const *,unsigned int))

Comparing the functions prototype listed in the dump to the one listed in the error message the expanded prototype seems to match however the mangled names do not.

err ?ComputeCrc16@@$$FYAGPBXI@Z unsigned short __cdecl ComputeCrc16(void const *,unsigned int)
dump?ComputeCrc16@@YAGPBXI@Z    unsigned short __cdecl ComputeCrc16(void const *,unsigned int)

In the LNK2028 link it mentions problems with _cdecl being called with __clrcall but it says this occurs when calling an exported native function, however it doesn't describe how to resolve the issue. Besides I'm compiling both the called DLL and the calling DLL with /clr so neither of the calling or the called function should be native to my understanding.

The calling code looks like this

unsigned short __declspec(dllimport) ComputeCrc16(const void * i_pData, size_t i_nBytes);

short CPrivateUdpPkt::ComputeCrc() const
{
    const Byte * pByte = reinterpret_cast<const Byte *>(&m_Crc) + sizeof(m_Crc);
    size_t len = &m_aData[DataLen()] - pByte;
    return ComputeCrc16(pByte, len);
}

The called function looks like this:

unsigned short __declspec(dllexport) ComputeCrc16(const void * i_pData, size_t i_unNumBytes)
{
...
}

来源:https://stackoverflow.com/questions/11019791/lnk2028-managed-c-dll-calling-function-in-another-managed-c-dll

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!