I'm converting an old C/C++ utility library to managed IJW DLL. Trying to understand link error LNK2020. I have a C/C++ static library now being compiled as a DLL with /CLR and a console app with the utility lib DLL as reference. I get unresolved token on all of my C functions in the DLL. I don't get link error for the one ref class I have in the library DLL.
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
When I use dumpbin /exports on the utility DLL assembly, I get no exported symbols.
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
When I use dumpbin /relocations I do see the undefined function and the prototype exactly matches the LNK2020 error message.
FE5 HIGHLOW 100365E4 __mep@
?Reallocx@BwLibM@@$$FYMXPAPAXIP$AAVString@System@@I@Z ([MEP]
void __clrcall BwLibM::Reallocx(void * *,unsigned int,class System::String ^,unsigned int))
Should I be seeing the function in the dumpbin /export output? I tried exporting the functions using classic DLL import/export technique with __declspec(dllexport) and __declspec(dllimport) but got the error
Error 1 error C3395: 'BwLibM::Reallocx' : __declspec(dllexport) cannot be applied to a function with the __clrcall calling convention C:\ICL5K\BwLibM\REALLOCX.CPP 34 1 BwLibM
Source to one of the utility functions looks like this: 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);
. . .
}
I posted a similar issue a few months ago where the solution was to set character set on library and application to Multi-Byte. In this case DLL and Console App are set to Multi-Byte Character Set and linker error persists.