Visual Studio 2010中Visual C ++中的LNK 2005 [英] LNK 2005 in Visual C++ in Visual Studio 2010
问题描述
我试图在MS VS 2010中编译使用Visual C ++ 2005和MFC编写的C ++程序.可悲的是,在编译过程中出现以下错误:
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:
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有一个头文件,其中包含CMemDCImpl类的所有成员的定义以及* .cpp文件及其实现.请帮助我解决此错误.
CMemDCImpl has a header file which contains definitions of all members of the class CMemDCImpl, and *.cpp file with their implementations. Please help me to fix this error.
推荐答案
您提到CMemDCImpl是在cpp文件中定义的.但是,它似乎也定义在uafxcwd.lib(您显然使用的库)中. 我可以想到此错误的两种可能性:
You mention that you CMemDCImpl is defined in a cpp file. However, it also seems to be defined in uafxcwd.lib (a library you apparently use). I can think of two possibilities for this error:
- 您要包含尝试使用的库的cpp.通常,当您使用预编译的库时,只需在链接时在您自己的源文件和库中引用头文件.您是否可能在自己的项目中包含了库的源.cpp文件?如果是这种情况,只需从项目中删除源.cpp文件.
- 您要定义自己的类,该类的名称与您在库中引用的名称相同,并且名称冲突.解决此问题的首选方法是将您自己定义的类封装在名称空间中:
.
namespace Foo
{
class CMemDC
{
// ...
};
}
// Usage:
Foo::CMemDC myMemDC;
这篇关于Visual Studio 2010中Visual C ++中的LNK 2005的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!