LNK 2005 in Visual C ++ in Visual Studio 2010

I am trying to compile a C ++ program written using Visual C ++ 2005 and MFC in MS VS 2010. Unfortunately, during compilation I get the following error:

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 that contains definitions of all members of the CMemDCImpl class and * .cpp file with their implementations. Please help me fix this error.

+7
source share
3 answers

You mentioned that you CMemDCImpl are defined in the cpp file. However, it is also defined in uafxcwd.lib (the library that you are apparently using). I can imagine two possibilities for this error:

  • You include the cpp library that you are trying to use. Usually, when you use a precompiled library, you only need to reference the header file in your source file and in the library at the time of the link. Is it possible that you included the source .cpp library files in your own project? If so, just delete the source .cpp files from your project.
  • You define your own class that has the same name as the one you reference in the library, and you have a name clash. The preferred method to fix this problem is to encapsulate the class that you defined in the namespace:

.

 namespace Foo { class CMemDC { // ... }; } // Usage: Foo::CMemDC myMemDC; 
+6
source

Without real code, we can only guess. You most likely did one of the following:

  • Implemented CMemDC::~CMemDC() {} twice, perhaps a copy-paste that you did not rename to CMemDCImpl::~CMemDCImpl()
  • Implemented CMemDC::~CMemDC() in the header file after defining the CMemDC class instead of the class definition
+3
source

Decision. I use: rename the well-known and well-used CMemDC class to something like CMemDc

because Microsoft smashed it, and Kit or they themselves did not protect the copyright?!?

in vs2k10 Microsoft decided to crush the CMemDC class name Keith with some shit.

The guys from Microsoft were born yesterday: this is one of the most popular classes that everyone has been using since 1997! Gross! Shame on you, Microsoft!

CMemDc - DC memory

// Posted by Keith Rule

// Email: keithr@europa.com

// Copyright 1996-1997, Keith Rule

Thanks Kate! These "new" and "catastrophic" guys from "after Gates" want us to change every "CMemDC" in every source that we have. What a disgrace

+1
source

All Articles