Link error linking from managed to unmanaged C++ despite linking to .lib file with exported symbols

╄→尐↘猪︶ㄣ 提交于 2019-12-31 04:05:45

问题


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:


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).


来源:https://stackoverflow.com/questions/11531695/link-error-linking-from-managed-to-unmanaged-c-despite-linking-to-lib-file-wi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!