在新类上调用 RUNTIME_CLASS 时出现链接错误
我有一个在 MFC 上完成的 Visual Studio 2010 项目。我收到这些错误:
2>COrderContentsItemsDocument.obj : error LNK2028: unresolved token (0A0001CA) "public: static struct CRuntimeClass * __stdcall COrderContentsItem::GetThisClass(void)" (?GetThisClass@COrderContentsItem@@$$FSGPAUCRuntimeClass@@XZ) referenced in function "public: virtual struct CRuntimeClass * __thiscall COrderContentsItemsDocument::GetItemsRuntimeClass(void)" (?GetItemsRuntimeClass@COrderContentsItemsDocument@@$$FUAEPAUCRuntimeClass@@XZ)
2>COrderContentsItemsDocument.obj : error LNK2019: unresolved external symbol "public: static struct CRuntimeClass * __stdcall COrderContentsItem::GetThisClass(void)" (?GetThisClass@COrderContentsItem@@$$FSGPAUCRuntimeClass@@XZ) referenced in function "public: virtual struct CRuntimeClass * __thiscall COrderContentsItemsDocument::GetItemsRuntimeClass(void)" (?GetItemsRuntimeClass@COrderContentsItemsDocument@@$$FUAEPAUCRuntimeClass@@XZ)
2>..\..\Output\Win32\Debug_Unicode\MindSalesManager.exe : fatal error LNK1120: 2 unresolved externals
经过一番研究,我发现,当我调用时,问题就出现了,
RUNTIME_CLASS(COrderContentsItem)
所以,这个类是我从另一个已经存在的类中复制的新类。所以我想知道问题出在哪里。
干杯, 塞尔吉奥
I have a Visual Studio 2010 project done on MFC. I receive these errors:
2>COrderContentsItemsDocument.obj : error LNK2028: unresolved token (0A0001CA) "public: static struct CRuntimeClass * __stdcall COrderContentsItem::GetThisClass(void)" (?GetThisClass@COrderContentsItem@@$FSGPAUCRuntimeClass@@XZ) referenced in function "public: virtual struct CRuntimeClass * __thiscall COrderContentsItemsDocument::GetItemsRuntimeClass(void)" (?GetItemsRuntimeClass@COrderContentsItemsDocument@@$FUAEPAUCRuntimeClass@@XZ)
2>COrderContentsItemsDocument.obj : error LNK2019: unresolved external symbol "public: static struct CRuntimeClass * __stdcall COrderContentsItem::GetThisClass(void)" (?GetThisClass@COrderContentsItem@@$FSGPAUCRuntimeClass@@XZ) referenced in function "public: virtual struct CRuntimeClass * __thiscall COrderContentsItemsDocument::GetItemsRuntimeClass(void)" (?GetItemsRuntimeClass@COrderContentsItemsDocument@@$FUAEPAUCRuntimeClass@@XZ)
2>..\..\Output\Win32\Debug_Unicode\MindSalesManager.exe : fatal error LNK1120: 2 unresolved externals
After some research, I disocovered,that the problem comes when I call
RUNTIME_CLASS(COrderContentsItem)
So, this class is a new one that I copied from another already existing. So I am wondering to discover what is the problem.
Cheers,
Sérgio
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决方案是更改 COrderContentsItem.cpp 文件属性。在解决方案资源管理器中,右键单击该文件,选择“属性”,然后在“配置属性”>“配置属性”中选择“属性”。一般将项目类型从“C/C++ header”更改为“C/C++ compiler”。
可能是我在创建文件时做错了什么,例如选择 .h 文件而不是 .cpp 文件。
The solution is to change the COrderContentsItem.cpp file properties. On solution Explorer, right-click the file, Choose Properties, and in Configration Properties > General change the Item type from "C/C++ header" to "C/C++ compiler".
May be I did something wrong when creating the file, e. g. choosing .h file instead of .cpp file.