1
votes

Despite following various posts on using and linking to unmanaged C++ code from a C++/CLI wrapper dll, I cannot resolve these link issues.

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 a unmanaged native C++ dll with a simple class, exporting/importing symbols accordingly

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

class DLL_PUBLIC MyClass { . . . };

And I can see .dll and .lib linker file being generated after building.

Then I have the managed C++/CLI wrapper project (also a dll), which links to the MyClass.lib in the Linker->Input->Additional Dependencies setting. Also included the .h file from MyClass in the wrapper project, and I can see the sln can see MyClass.h file.

// MyClassAdaptor.h

#include "MyClass.h"

namespace WrapperLayer
{
    public ref class MyClassAdaptor 
    { 
      . . . 
    private:
        MyClass* _myclass;  
    }; 
}

What can possibly be missing?

1
Was the unmanaged code built with VC++ 2010 as well?ildjarn
So, silly question, but... you have actually implemented the constructor and destructor, right?Ed S.
Yes, I did for both MyClass and MyClassWrapper. Would it be possible the compiler only sees MyClass.lib but not MyClass.dll?M W

1 Answers

1
votes

Few points:

  • Use Dependency Walker for the DLL and check if those symbols are actually in DLL.
  • Ensure you are using correct lib file - a 32-bit LIB cannot be used for 64-bit build.
  • Ensure the .CPP file used to build the class is actually unmanaged one (or the DLL itself, as a whole, is unmanaged).