简体   繁体   English

Visual Studio 2010中的Visual C ++中的LNK 2005

[英]LNK 2005 in Visual C++ in Visual Studio 2010

I'm trying to compile a C++ program, written using Visual C++ 2005 and MFC, in MS VS 2010. Sadly I'm getting the following error during compilation: 我正在尝试编译在MS VS 2010中使用Visual C ++ 2005和MFC编写的C ++程序。遗憾的是,我在编译期间遇到以下错误:

Error 2 error LNK2005: "public: virtual __thiscall CMemDC::~CMemDC(void)" (??1CMemDC@@UAE@XZ) already defined in CMemDCImpl.obj Project\Project\Project\uafxcwd.lib(afxglobals.obj) Project.

CMemDCImpl has a header file which contains definitions of all members of the class CMemDCImpl, and *.cpp file with their implementations. CMemDCImpl有一个头文件,其中包含类CMemDCImpl的所有成员的定义,以及包含其实现的* .cpp文件。 Please help me to fix this error. 请帮我修复此错误。

You mention that you CMemDCImpl is defined in a cpp file. 您提到CMemDCImpl是在cpp文件中定义的。 However, it also seems to be defined in uafxcwd.lib (a library you apparently use). 但是,它似乎也在uafxcwd.lib(您显然使用的库)中定义。 I can think of two possibilities for this error: 我可以想到这个错误的两种可能性:

  1. You're including the cpp of the library you're attempting to use. 您要包含您尝试使用的库的cpp。 Usually, when you use a precompiled library, you only need to reference the header file in your own source file and the library at link time. 通常,在使用预编译库时,只需在链接时引用自己的源文件和库中的头文件。 Is it possible that you included the source .cpp files of the library in your own project? 是否有可能在您自己的项目中包含库的源.cpp文件? If this is the case, simply remove the source .cpp files from your project. 如果是这种情况,只需从项目中删除源.cpp文件即可。
  2. You're defining a class of your own that has the same name as the one you're referencing in the library and you have a name clash. 您正在定义一个自己的类,它与您在库中引用的类名称相同,并且您有一个名称冲突。 The preferred method to fix this issue is to encapsulate the class you defined yourself in a namespace: 解决此问题的首选方法是将您自己定义的类封装在命名空间中:

.

namespace Foo
{
    class CMemDC
    {
        // ...
    };
}

// Usage:
Foo::CMemDC myMemDC;

Without the actual code, we can only guess. 没有实际代码,我们只能猜测。 Most likely you have done one of these: 很可能你做过以下其中一种:

  • Implemented CMemDC::~CMemDC() {} twice, maybe a copy-paste that you didn't rename to CMemDCImpl::~CMemDCImpl() 实现了CMemDC::~CMemDC() {}两次,也许你没有重命名为CMemDCImpl::~CMemDCImpl()的复制粘贴CMemDCImpl::~CMemDCImpl()
  • Implemented CMemDC::~CMemDC() in a header file after CMemDC class definition instead of in the class definition CMemDC类定义之后而不是类定义中的头文件中实现CMemDC::~CMemDC()

Solution I use : rename the well known and well used CMemDC class in something as CMemDc 我使用的解决方案:将已知且使用良好的CMemDC类重命名为CMemDc

because Microsoft crushed it and Keith or ourselves have not copyrighted it ?!? 因为微软粉碎了它,基思或我们自己没有受版权保护吗?!?

in vs2k10 Microsoft dared to crush the name of the CMemDC class of Keith, with some shit. 在vs2k10中,微软敢于粉碎基思的CMemDC类名称。

Yesterday born Microsoft guys : this it's one of the most popular classes that everyone uses since 1997! 昨天出生的微软家伙:这是自1997年以来每个人都使用的最受欢迎的课程之一! Gross! 毛! Shame on you, Microsoft ! 羞辱你,微软!

CMemDc - memory DC CMemDc - 内存DC

// Author: Keith Rule //作者:基思规则

// Email: keithr@europa.com //电子邮件:keithr@europa.com

// Copyright 1996-1997, Keith Rule //版权所有1996-1997,Keith Rule

Thank You Keith ! 谢谢基思! Those "new" and "catastrophic" guys of "the after-Gates" want us to change every "CMemDC" in every sources we have.. What a shame 那些“后盖茨”的“新”和“灾难性”家伙希望我们改变我们所有来源的每一个“CMemDC”。真可惜

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM