本文介绍了来自我的MFC / CLI项目的LNK2005错误(本机和托管代码)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 您好b $ b 我有一个来自MFC / C ++ VS2010的项目,但我需要在我的项目中使用.NET Library。实际上我需要同时拥有本机和管理代码。所以我试图使用CLI / C ++工具和集成,为此我从VS2010创建了空CLI项目,然后我在这个项目中添加了我所有的MFC源,但是当我想构建它时,我得到这些错误: 错误4错误LNK2005:public:virtual int __thiscall CComboEdit :: PreTranslateMessage(struct tagMSG *)(?PreTranslateMessage @ CComboEdit @@ UAEHPAUtagMSG @ @@ Z)已在InPlaceList.obj中定义D:\ KTC \ EWS \Source \ EWS-CLI\EngSystem\EngSystem \ GridCellCombo.obj EngSystem 错误16错误LNK2005:protected:void __thiscall CInPlaceList :: OnKeyUp(unsigned int,unsigned int,unsigned int)(?OnKeyUp @ CInPlaceList @@ IAEXIII @ Z)已在InPlaceList.obj D:\ KTC \ EWS \Source \EWS-CLI \EngSystem\EngSystem\GridCellCombo.obj EngSystem 错误15错误LNK2005:protected:void __thiscall CInPlaceList :: OnKeyDown(unsigned int,un signed int,unsigned int)(?OnKeyDown @ CInPlaceList @@ IAEXIII @ Z)已在InPlaceList.obj中定义D:\ KTC \ EWS \Source \EWS-CLI\EngSystem \EngSystem \ GridCellCombo。 obj EngSystem 错误12错误LNK2005:protected:虚拟结构AFX_MSGMAP const * __thiscall CInPlaceList :: GetMessageMap(void)const(?GetMessageMap @ CInPlaceList @@ MBEPBUAFX_MSGMAP @ @XZ)已经在InPlaceList.obj中定义了D:\ KTC \ EWS \ Source \ EWS-CLI \EngSystem\EngSystem\GridCellCombo.obj EngSystem 错误17错误LNK1561:必须定义入口点D:\ KTC \ EWS \Source \EWS-CLI\EngSystem\EngSystem\LINK EngSystem 另外来自GridCellCombo.cpp我有这些库 # include ../ stdAfx.h #include ../ UserView.h #include ../ GridCtrl_src / GridCell.h #include .. /GridCtrl_src/GridCtrl.h #include GridCellCombo.h #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE 静态 char 这个_FILE [] = __FILE__; #endif 任何帮助都将不胜感激。 b $ b 最好的问候。 Homay 解决方案 不知怎的,你包括了一些你的来源两次。这可能发生在许多场景中,但这是我的第一个猜测: - 你有一个或多个方法在头文件而不是.cpp文件中实现(不是一个很好的方法来实现它)。头文件至少包含两次(这部分并不罕见)。 - 您的项目中包含两次源文件。 - 一些奇怪的东西可以有时会发生如果你的基类在一个dll中实现而派生类在不同的dll中(需要更多细节)。 - ... 另外,如果你有一个混合模式DLL,我相信VS2010需要从/ CLR可执行文件中调用它(我用VS2005完成了这个,但是Microsoft将规则从版本更改为版本而我不是100与VS2010规则的百分比)。我认为VS2010仍然需要先进行.exe混合模式,然后链中的所有DLL从可执行文件到上面描述的DLL。没有非托管DLL可以调用托管代码。您的混合模式DLL可以调用托管代码或非托管代码。 [如果我在这里说了不对的话,任何人都可以随意进入并纠正我... ] HiI have a project from the MFC/C++ VS2010, but I need to use ".NET Library" inside of my project. Actually I need to have a native and manged code at same time. So I am trying to use CLI/C++ facilities and integration, for that purpose I created "Empty CLI" project from the VS2010 and then I added all of my MFC source inside of this project, But When I want to the build it, I get these errors: Error4error LNK2005: "public: virtual int __thiscall CComboEdit::PreTranslateMessage(struct tagMSG *)" (?PreTranslateMessage@CComboEdit@@UAEHPAUtagMSG@@@Z) already defined in InPlaceList.objD:\KTC\EWS\Source\EWS-CLI\EngSystem\EngSystem\GridCellCombo.objEngSystemError16error LNK2005: "protected: void __thiscall CInPlaceList::OnKeyUp(unsigned int,unsigned int,unsigned int)" (?OnKeyUp@CInPlaceList@@IAEXIII@Z) already defined in InPlaceList.objD:\KTC\EWS\Source\EWS-CLI\EngSystem\EngSystem\GridCellCombo.objEngSystemError15error LNK2005: "protected: void __thiscall CInPlaceList::OnKeyDown(unsigned int,unsigned int,unsigned int)" (?OnKeyDown@CInPlaceList@@IAEXIII@Z) already defined in InPlaceList.objD:\KTC\EWS\Source\EWS-CLI\EngSystem\EngSystem\GridCellCombo.objEngSystemError12error LNK2005: "protected: virtual struct AFX_MSGMAP const * __thiscall CInPlaceList::GetMessageMap(void)const " (?GetMessageMap@CInPlaceList@@MBEPBUAFX_MSGMAP@@XZ) already defined in InPlaceList.objD:\KTC\EWS\Source\EWS-CLI\EngSystem\EngSystem\GridCellCombo.objEngSystemError17error LNK1561: entry point must be definedD:\KTC\EWS\Source\EWS-CLI\EngSystem\EngSystem\LINKEngSystemAdditionally from the GridCellCombo.cpp I have these library#include "../stdAfx.h"#include "../UserView.h"#include "../GridCtrl_src/GridCell.h"#include "../GridCtrl_src/GridCtrl.h"#include "GridCellCombo.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endifany help would be appreciated.Best Regards.Homay 解决方案 Somehow you are including some of your source twice. This can happen from a number of scenarios but here are my first guesses:- You have one or more of the methods implemented in header files instead of the .cpp files (not a good way to do it). The header files are included at least twice somewhere (this part is not uncommon).- You have a source file included twice in your project.- Some bizarre things can sometimes happen if your base class is implemented in one dll and a derived class is in a different dll (more details required).- ...Also, if you have a mixed mode DLL, I believe with VS2010 it needs to be called from a /CLR executable (I have done this with VS2005, but Microsoft changes the rules from version to version and I am not 100% with what the rules are for VS2010). I think it is still correct with VS2010 that you need to first make your .exe mixed mode, then all DLLs in the chain from executable to the DLL you are describing above. No unmanaged DLLs can call managed code. Your mixed mode DLLs can call either managed or unmanaged code.[If I have said something incorrect here, anybody please feel free to jump in and correct me...] 这篇关于来自我的MFC / CLI项目的LNK2005错误(本机和托管代码)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-30 08:33