尽管链接到具有导出符号的.lib文件,仍然从管理链接到非托管C ++的链接错误
尽管有关于使用和链接到C ++ / CLI包装器dll中的非托管C ++代码的各种帖子,我无法解决这些链接问题。
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)
我有一个非托管的本地C ++ dll与一个简单的类,导出/导入符号
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 { . . . };
我可以看到.dll和.lib链接器文件生成后生成。
And I can see .dll and .lib linker file being generated after building.
然后我有一个托管的C ++ / CLI包装项目(也是一个dll),链接到Linker-> Input-> Additional Dependencies设置中的MyClass.lib。在包装器项目中还包括MyClass的.h文件,我可以看到sln可以看到MyClass.h文件。
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;
};
}
可能缺少什么?
几点:
- 对DLL使用Dependency Walker,并检查这些符号是否真的在DLL中。
- 确保您使用的是正确的lib文件 - 32位LIB不能用于64位构建。
- 确保使用.CPP文件构建类实际上是非托管的(或DLL本身,作为一个整体,是非托管)。