?
Solved

MFC: linking error

Posted on 2011-05-04
2
Medium Priority
?
1,672 Views
Last Modified: 2012-05-11
Dear experts,

My application worked fine, but suddenly started giving me

5>nafxcw.lib(afxglobals.obj) : error LNK2005: "public: virtual __thiscall CMemDC::~CMemDC(void)" (??1CMemDC@@UAE@XZ) already defined in WaveFormDialog.obj
5>.\Release/Book.exe : fatal error LNK1169: one or more multiply defined symbols found

I didn't do any changes at all. Just rebuilt the project. Could you please tell me how I could fix that?
CMemDC::~CMemDC(void) is defined in MemDC.h, and WaveFormDialog.cpp has
#include "MemDC.h"
0
Comment
Question by:tantormedia
2 Comments
 
LVL 16

Accepted Solution

by:
HooKooDooKu earned 2000 total points
ID: 35691675
It sounds like you are trying to define your own version of CMemDC when MFC already has one defined.  MFC didn't originally define a CMemDC class.  So if you recently upgraded MFC or installed a service pack, I could see where a new conflict might occur without any changes to your source code.

If you don't have your own CMemDC class defined, then you shouldn't need #include "MemDC.h" because it should already be included when you included "stdafx.h".

If you do have your own CMemDC class, then you need to either rename it or place it in your own namespace to resolve the conflict.

The quickest way to fix it with your own name space is to enclose the declaration of your CMemDC class (.h part) and the definition of CMemDC (.cpp part) inside a namespace...

#include "stdafx.h"
namespace MySpace{
class CMemDC::CDC
{
...
};
} //end of MySpace... no closing ;

//Do the same thing for the .cpp source code of your CMemDC.

 Then anywhere you are using your CMemDC, replace CMemDC with MySpace::CMemDC.  There is the 'using' key word that I think allows you to avoid having specify the name space with every instance of CMemDC, but I have not researched the 'using' keyword enough to advize you at this time.
0
 

Author Closing Comment

by:tantormedia
ID: 35692100
Thank you very much. Yes, this problem appeared after an upgrade today. I just renamed MemDC of my own, and the trouble is gone.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question