问题
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