我正在将旧的C / C实用程序库转换为托管的IJW DLL . 试图理解链接错误LNK2020 . 我有一个C / C静态库现在被编译为带有/ CLR的DLL和一个控制台应用程序,实用程序lib DLL作为参考 . 我在DLL中的所有C函数上都得到了未解析的标记 . 我没有得到我在库DLL中的一个ref类的链接错误 .

Error   1   error LNK2020: unresolved token (0A00000B) 
"void __clrcall BwLibM::Reallocx(void * *,unsigned int,class System::String ^,unsigned int)" (
?Reallocx@BwLibM@@$$FYMXPAPAXIP$AAVString@System@@I@Z)  C:\ICL5K\ICL5K\OPENSOUR.obj ICL5K

当我在实用程序DLL程序集上使用dumpbin / exports时,我没有导出符号 .

Microsoft (R) COFF/PE Dumper Version 11.00.50727.1
Copyright (C) Microsoft Corporation.  All rights reserved.

Dump of file bwlibm.dll
File Type: DLL
  Summary
        4000 .data
       26000 .rdata
        1000 .reloc
        3000 .rsrc
        F000 .text

当我使用dumpbin / relocations时,我确实看到了未定义的函数,原型与LNK2020错误消息完全匹配 .

FE5  HIGHLOW 100365E4  __mep@
?Reallocx@BwLibM@@$$FYMXPAPAXIP$AAVString@System@@I@Z ([MEP] 
 void __clrcall BwLibM::Reallocx(void * *,unsigned int,class System::String ^,unsigned int))

我应该在dumpbin / export输出中看到这个函数吗?我尝试使用经典的DLL导入/导出技术导出函数__declspec(dllexport)和__declspec(dllimport)但是得到了错误

错误1错误C3395:'BwLibM :: Reallocx':__ declspec(dllexport)无法应用于具有__clrcall调用约定的函数C:\ ICL5K \ BwLibM \ REALLOCX.CPP 34 1 BwLibM

其中一个实用程序函数的源代码如下:Reallocx.cpp

namespace BwLibM {
    void Reallocx(void **ptr, size_t nBytesI, System::String^ file, unsigned line)
    {
     . . .
    }
} // namespace BwLibM

=== BwLibM.h ==

namespace BwLibM {
 . . .
void Reallocx(void **ptr, size_t nBytesI, System::String^ file, unsigned line);
 . . .
}

我在几个月前发布了类似的issue,解决方案是将库和应用程序上的字符集设置为Multi-Byte . 在这种情况下,DLL和控制台应用程序设置为多字节字符集,并且链接器错误仍然存在 .