如何解决LNK2001
我有一组用 VS 6 编写的代码。我正在尝试在 VS 2008 中为其编写一个 CLI 包装器。我在 CLI 代码中包含了一个 VS6 头文件并进行了编译。
编译时我得到LNK2001: 无法解析的外部符号“public: virtual void __thiscall Someclass::SomeMethod(SomeObject& os)
。
当我在错误中搜索方法和类时,它对应于代码,
CPP
class SomeClass: public ParentClass
{
virtual void SomeMethod(SomeObject& os);
}
文件
void SomeClass::SomeMethod(SomeObject& os)
{
//Implementation here
}
SomeMethod 实际上是从 ParentClass 中覆盖的,
当我在中进行声明时。 但是我不能这样做,
virtual void SomeMethod(SomeObject& os) {};
因为它会导致一个方法有两个主体。为什么会出现这种情况?或者我是否必须添加任何内容? #pragma 同时在 CLI 中包含 BS6 标头?
I have a set of code written in VS 6. I am trying to write a CLI wrapper for that in VS 2008. I included one of the VS6 header files in the CLI code and compiled.
While compiling I am getting
LNK2001: unresolved external symbol "public: virtual void __thiscall Someclass::SomeMethod(SomeObject& os)
.
When I searched for the method and the class in the error it correponds to the code,
Header File.
class SomeClass: public ParentClass
{
virtual void SomeMethod(SomeObject& os);
}
CPP File
void SomeClass::SomeMethod(SomeObject& os)
{
//Implementation here
}
SomeMethod is actually overridden from the ParentClass
When I make the declaration in the header file by adding a open and close curly braces as
virtual void SomeMethod(SomeObject& os) {};
the error disappears. But I cannot do that since it would result in one method having two bodies. Why is this behavior? How do I overcome this? Or Do I have to put any #pragma while including BS6 headers in CLI?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来您的项目中没有包含“CPP 文件”。这也可以解释为什么当你有两个主体时你不会收到错误。要检查这一点,请尝试在 CPP 文件中故意添加编译错误。如果编译器没有抱怨,那就证明你没有编译 CPP 文件。
Sounds like you've not included 'CPP File' in your project. That would also explain why you don't get an error when you have two bodies. To check this try putting a deliberate compile error in CPP File. If the compiler doesn't complain that would prove that you aren't compiling CPP File.