包装 C++带有托管类的 DLL
我试图用托管 C++ 包装非托管 C++ DLL,但不断收到链接错误。
即使我在项目中包含我的library.lib 并包含正确的头文件。
这是托管类:
#pragma once
#include "..\Terminal\Terminal.h"
public ref class ManagedTerminal
{
private:
Terminal * m_unTerminal;
public:
ManagedTerminal(void)
{
m_unTerminal = new Terminal();
}
};
这是非托管类:
#include "..\Core1.h"
#include "..\Core2.h"
__declspec(dllexport) class Terminal
{
private:
CoreObj m_core;
public:
Terminal();
void Init(char* path, char* filename);
void Start();
void Stop();
void Run();
Array<Report> GetSnapshot();
~Terminal(void);
};
我得到的错误是:
Error 5 error LNK2028: unresolved token (0A0000B3) "public: __thiscall Terminal::Terminal(void)" (??0Terminal@@$$ FQAE@XZ) 在函数“public: __clrcall ManagedTerminal::ManagedTerminal(void)”中引用 (??0ManagedTerminal@@$$FQ$AAM@XZ) ManagedTerminal.obj TerminalWrapper
错误 6 错误 LNK2019:无法解析的外部符号“public: __thiscall Terminal ::Terminal(void)" (??0Terminal@@$$FQAE@XZ) 在函数 "public: __clrcall ManagedTerminal::ManagedTerminal(void)" (??0ManagedTerminal@@$$FQ$AAM@XZ) ManagedTerminal 中引用。 obj TerminalWrapper
有人能告诉我出了什么问题吗? 谢谢 :)
I'm trying to wrap a unmanaged C++ DLL with managed C++ and I keep getting linking errors.
even though I include my library.lib in the project and include the correct header file.
This is the managed class:
#pragma once
#include "..\Terminal\Terminal.h"
public ref class ManagedTerminal
{
private:
Terminal * m_unTerminal;
public:
ManagedTerminal(void)
{
m_unTerminal = new Terminal();
}
};
and this is the unmanaged class:
#include "..\Core1.h"
#include "..\Core2.h"
__declspec(dllexport) class Terminal
{
private:
CoreObj m_core;
public:
Terminal();
void Init(char* path, char* filename);
void Start();
void Stop();
void Run();
Array<Report> GetSnapshot();
~Terminal(void);
};
and the errors I get are:
Error 5 error LNK2028: unresolved token (0A0000B3) "public: __thiscall Terminal::Terminal(void)" (??0Terminal@@$$FQAE@XZ) referenced in function "public: __clrcall ManagedTerminal::ManagedTerminal(void)" (??0ManagedTerminal@@$$FQ$AAM@XZ) ManagedTerminal.obj TerminalWrapper
Error 6 error LNK2019: unresolved external symbol "public: __thiscall Terminal::Terminal(void)" (??0Terminal@@$$FQAE@XZ) referenced in function "public: __clrcall ManagedTerminal::ManagedTerminal(void)" (??0ManagedTerminal@@$$FQ$AAM@XZ) ManagedTerminal.obj TerminalWrapper
can anybody tell me what's wrong?
thanks :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须匹配所有构建设置——特别是调用约定(CDECL 与 STDCALL)——才能获得成功的链接。
从 .NET 2.0 开始,您还必须动态链接到 c 运行时,因此请确保 .dll 和托管 C++ 项目都执行此操作。
基本上,进入两个项目的属性对话框并确保影响调用的内容相同。
You have to match all of the build settings -- specifically the calling conventions (CDECL vs. STDCALL) -- in order to have a successful link.
Since .NET 2.0, you have also had to link to the c-runtime dynamically, so make sure that both the .dll and the managed C++ project do this.
Basically, go into the properties dialog for both projects and make sure that things that affect the call are the same.