Error link related to managed to unmanaged C ++, despite link to .lib file with exported characters

Despite the following messages about using and linking to unmanaged C ++ code from a dll of a C ++ / CLI shell, I cannot solve these link problems.

1>MyClassAdapter.obj : error LNK2028: unresolved token (0A00000A) "public: __thiscall MyClass::~MyClass(void)" ( ??1MyClass@ @ $$FQAE@XZ ) referenced in function "public: void * __thiscall MyClass::`scalar deleting destructor'(unsigned int)" ( ??_GMyClass@ @ $$FQAEPAXI@Z ) 1>MyClassAdapter.obj : error LNK2028: unresolved token (0A00000B) "public: __thiscall MyClass::MyClass(void)" ( ??0MyClass@ @ $$FQAE@XZ ) referenced in function "public: __clrcall WrapperLayer::MyClassAdaptor::MyClassAdaptor(void)" ( ??0MyClassAdaptor@WrapperLayer @@ $$FQ$AAM@XZ ) 1>MyClassAdapter.obj : error LNK2019: unresolved external symbol "public: __thiscall MyClass::MyClass(void)" ( ??0MyClass@ @ $$FQAE@XZ ) referenced in function "public: __clrcall WrapperLayer::MyClassAdaptor::MyClassAdaptor(void)" ( ??0MyClassAdaptor@WrapperLayer @@ $$FQ$AAM@XZ ) 1>MyClassAdapter.obj : error LNK2019: unresolved external symbol "public: __thiscall MyClass::~MyClass(void)" ( ??1MyClass@ @ $$FQAE@XZ ) referenced in function "public: void * __thiscall MyClass::`scalar deleting destructor'(unsigned int)" ( ??_GMyClass@ @ $$FQAEPAXI@Z ) 

I have an unmanaged native C ++ dll with a simple class exporting / importing characters respectively

 // MyClass.h #ifdef _EXPORTING #define DLL_PUBLIC __declspec(dllexport) #else #define DLL_PUBLIC __declspec(dllimport) #endif class DLL_PUBLIC MyClass { . . . }; 

And I can see the DLL and the .lib linker file created after the build.

Then I have a managed C ++ / CLI shell project (also a DLL) that references MyClass.lib in the setting Linker-> Input-> Additional Dependencies. Also included is the .h file from MyClass in the shell project, and I see that sln can see the MyClass.h file.

 // MyClassAdaptor.h #include "MyClass.h" namespace WrapperLayer { public ref class MyClassAdaptor { . . . private: MyClass* _myclass; }; } 

What could be missing?

+1
source share
1 answer

A few points:

  • Use Dependency Walker for the DLL and check if these characters are actually in the DLL.
  • Make sure you use the correct lib file - the 32-bit LIB cannot be used for 64-bit builds.
  • Make sure that the .CPP file used to build the class is actually unmanaged (or the DLL itself is generally unmanaged).
+1
source

Source: https://habr.com/ru/post/890416/


All Articles