儘管以下關於使用和鏈接到來自C++/CLI包裝DLL的非託管C++代碼的各種帖子,我無法解決這些鏈接問題,從託管到非託管C++鏈接錯誤。儘管鏈接到.lib文件與導出符號
1>MyClassAdapter.obj : error LNK2028: unresolved token (0A00000A) "public: __thiscall MyClass::~MyClass(void)" ([email protected]@[email protected]) referenced in function "public: void * __thiscall MyClass::`scalar deleting destructor'(unsigned int)" ([email protected]@[email protected])
1>MyClassAdapter.obj : error LNK2028: unresolved token (0A00000B) "public: __thiscall MyClass::MyClass(void)" ([email protected]@[email protected]) referenced in function "public: __clrcall WrapperLayer::MyClassAdaptor::MyClassAdaptor(void)" ([email protected]@@[email protected])
1>MyClassAdapter.obj : error LNK2019: unresolved external symbol "public: __thiscall MyClass::MyClass(void)" ([email protected]@[email protected]) referenced in function "public: __clrcall WrapperLayer::MyClassAdaptor::MyClassAdaptor(void)" ([email protected]@@[email protected])
1>MyClassAdapter.obj : error LNK2019: unresolved external symbol "public: __thiscall MyClass::~MyClass(void)" ([email protected]@[email protected]) referenced in function "public: void * __thiscall MyClass::`scalar deleting destructor'(unsigned int)" ([email protected]@[email protected])
我有一個非託管的本機C++的dll用一個簡單的類,因此導出/導入符號
// MyClass.h
#ifdef _EXPORTING
#define DLL_PUBLIC __declspec(dllexport)
#else
#define DLL_PUBLIC __declspec(dllimport)
#endif
class DLL_PUBLIC MyClass { . . . };
我能看到的.dll和建成後產生的.lib連接文件。
然後,我有託管的C++/CLI包裝器項目(也是一個dll),該項目鏈接到鏈接器 - >輸入 - >附加依賴項設置中的MyClass.lib。還在包裝器項目中包含MyClass的.h文件,我可以看到sln可以看到MyClass.h文件。
// MyClassAdaptor.h
#include "MyClass.h"
namespace WrapperLayer
{
public ref class MyClassAdaptor
{
. . .
private:
MyClass* _myclass;
};
}
什麼可能會丟失?
使用VC++ 2010構建的非託管代碼也是如此嗎? – ildjarn 2012-07-17 22:26:57
是的,這兩個DLL都是。 – 2012-07-17 22:28:28
所以,愚蠢的問題,但是......你實際上*實現了構造函數和析構函數,對吧? – 2012-07-17 22:37:40