最常见的20种VC++编译错误信息

1、fatal error C1010: unexpected end of file while looking for precompiled header directive。

寻找预编译头文件路径时遇到了不该遇到的文件尾。(一般是没有#include "stdafx.h")

2、fatal error C1083: Cannot open include file: 'R…….h': No such file or directory

不能打开包含文件“R…….h”:没有这样的文件或目录。

3、error C2011: 'C……': 'class' type redefinition

类“C……”重定义。

4、error C2018: unknown character '0xa3'

不认识的字符'0xa3'。(一般是汉字或中文标点符号)

5、error C2057: expected constant expression

希望是常量表达式。(一般出现在switch语句的case分支中)

6、error C2065: 'IDD_MYDIALOG' : undeclared identifier

“IDD_MYDIALOG”:未声明过的标识符。

7、error C2082: redefinition of formal parameter 'bReset'

函数参数“bReset”在函数体中重定义。

8、error C2143: syntax error: missing ':' before '{'

句法错误:“{”前缺少“;”。

9、error C2146: syntax error : missing ';' before identifier 'dc'

句法错误:在“dc”前丢了“;”。

10、error C2196: case value '69' already used

值69已经用过。(一般出现在switch语句的case分支中)

11、error C2509: 'OnTimer' : member function not declared in 'CHelloView'

成员函数“OnTimer”没有在“CHelloView”中声明。

12、error C2511: 'reset': overloaded member function 'void (int)' not found in 'B'

重载的函数“void reset(int)”在类“B”中找不到。

13、error C2555: 'B::f1': overriding virtual function differs from 'A::f1' only by return type or calling convention

类B对类A中同名函数f1的重载仅根据返回值或调用约定上的区别。

14、error C2660: 'SetTimer' : function does not take 2 parameters

“SetTimer”函数不传递2个参数。

15、warning C4035: 'f……': no return value

“f……”的return语句没有返回值。

16、warning C4553: '= =' : operator has no effect; did you intend '='?

没有效果的运算符“= =”;是否改为“=”?

17、warning C4700: local variable 'bReset' used without having been initialized

局部变量“bReset”没有初始化就使用。

18、error C4716: 'CMyApp::InitInstance' : must return a value

“CMyApp::InitInstance”函数必须返回一个值。

19、LINK : fatal error LNK1168: cannot open Debug/P1.exe for writing

连接错误:不能打开P1.exe文件,以改写内容。(一般是P1.Exe还在运行,未关闭)

20、error LNK2001: unresolved external symbol "public: virtual _ _thiscall C……::~C……(void)"

连接时发现没有实现的外部符号(变量、函数等)。

 

                    错误:error LNK2005 解决方法

2008-05-06 10:26

 

编译时链接错误如下:

MySAX2Handler.obj : error LNK2005: "public: __thiscall AttributeDetails::AttributeDetails(class AttributeDetails const &)" (??0AttributeDetails@@QAE@ABV0@@Z) already defined in usesax.obj

MySAX2Handler.obj : error LNK2005: "public: __thiscall ChildDetails::ChildDetails(class ChildDetails const &)" (??0ChildDetails@@QAE@ABV0@@Z) already defined in usesax.obj

MySAX2Handler.obj : error LNK2005: "public: __thiscall ElementDetails::ElementDetails(class ElementDetails const &)" (??0ElementDetails@@QAE@ABV0@@Z) already defined in usesax.obj

MySAX2Handler.obj : error LNK2005: "public: class ElementDetails __thiscall ElementDetails::operator=(class ElementDetails const &)" (??4ElementDetails@@QAE?AV0@ABV0@@Z) already defined in usesax.obj

MySAX2Handler.obj : error LNK2005: "int __cdecl run(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?run@@YAHV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) already defined in usesax.obj

MySAX2Handler.obj : error LNK2005: "class std::map<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class ElementDetails,struct std::less<class std::basic_string<char,struct std::char_traits<char>,class std::al

locator<char> > >,class std::allocator<class ElementDetails> > elementList" (?elementList@@3V?$map@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@VElementDetails@@U?$less@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@

2@V?$allocator@VElementDetails@@@2@@std@@A) already defined in usesax.obj

MySAX2Handler.obj : error LNK2005: "class std::stack<class StackEntry,class std::deque<class StackEntry,class std::allocator<class StackEntry> > > elementStack" (?elementStack@@3V?$stack@VStackEntry@@V?$deque@VStackEntry@@V?$allocator@VStackEntry@@@

std@@@std@@@std@@A) already defined in usesax.obj

..\..\bin/dtd.exe : fatal er

从CSDN找到的:

编程中经常能遇到LNK2005错误——重复定义错误,其实LNK2005错误并不是一个很难解决的错误。弄清楚它形成的原因,就可以轻松解决它了。

造成LNK2005错误主要有以下几种情况:

1.重复定义全局变量。可能存在两种情况:

A、对于一些初学编程的程序员,有时候会以为需要使用全局变量的地方就可以使用定义申明一下。其实这是错误的,全局变量是针对整个工程的。正确的应该是在一个CPP文件中定义如下:int g_Test;那么在使用的CPP文件中就应该使用:extern int g_Test即可,如果还是使用int g_Test,那么就会产生LNK2005错误,一般错误错误信息类似:AAA.obj error LNK2005 int book c?book@@3HA already defined in BBB.obj。切记的就是不能给变量赋值否则还是会有LNK2005错误。

这里需要的是“声明”,不是“定义”!根据C++标准的规定,一个变量是声明,必须同时满足两个条件,否则就是定义:

(1)声明必须使用extern关键字;(2)不能给变量赋初值

所以,下面的是声明:

extern int a;

下面的是定义

int a; int a = 0; extern int a =0;

B、对于那么编程不是那么严谨的程序员,总是在需要使用变量的文件中随意定义一个全局变量,并且对于变量名也不予考虑,这也往往容易造成变量名重复,而造成LNK2005错误。

2.头文件的包含重复。往往需要包含的头文件中含有变量、函数、类的定义,在其它使用的地方又不得不多次包含之,如果头文件中没有相关的宏等防止重复链接的措施,那么就会产生LNK2005错误。解决办法是在需要包含的头文件中做类似的处理:#ifndef MY_H_FILE //如果没有定义这个宏

#define MY_H_FILE //定义这个宏

……. //头文件主体内容

…….

#endif

上面是使用宏来做的,也可以使用预编译来做,在头文件中加入:

#pragma once

//头文件主体

3.使用第三方的库造成的。这种情况主要是C运行期函数库和MFC的库冲突造成的。具体的办法就是将那个提示出错的库放到另外一个库的前面。另外选择不同的C函数库,可能会引起这个错误。微软和C有两种C运行期函数库,一种是普通的函数库:LIBC.LIB,不支持多线程。另外一种是支持多线程的:msvcrt.lib。如果一个工程里,这两种函数库混合使用,可能会引起这个错误,一般情况下它需要MFC的库先于C运行期函数库被链接,因此建议使用支持多线程的msvcrt.lib。所以在使用第三方的库之前首先要知道它链接的是什么库,否则就可能造成LNK2005错误。如果不得不使用第三方的库,可以尝试按下面所说的方法修改,但不能保证一定能解决问题,前两种方法是微软提供的:

A、选择VC菜单Project->Settings->Link->Catagory选择Input,再在Ignore libraries 的Edit栏中填入你需要忽略的库,如:Nafxcwd.lib;Libcmtd.lib。然后在Object/library Modules的Edit栏中填入正确的库的顺序,这里需要你能确定什么是正确的顺序,呵呵,God bless you!

B、选择VC菜单Project->Settings->Link页,然后在Project Options的Edit栏中输入/verbose:lib,这样就可以在编译链接程序过程中在输出窗口看到链接的顺序了。

C、选择VC菜单Project->Settings->C/C++页,Catagory选择Code Generation后再在User Runtime libraray中选择MultiThread DLL等其他库,逐一尝试。

关于编译器的相关处理过程,参考:

http://www.donews.net/xzwenlan/archive/2004/12/23/211668.aspx

这就是我所遇到过的LNK2005错误的几种情况,肯定还有其他的情况也可能造成这种错误,所以我不希望你在看完这篇文章以后再遇到LNK2005错误时候,不动脑筋的想对号入座的排除错误。编程的过程就是一个思考的过程,所以还是多多开动你的头脑,那样收获会更多!  

从某人的博客找到的:

解决方案一:

把主函数所包含的操作函数.cpp,改为头文件.h,然后就可以解决如上错误。

解决方案二:

重新打开编译器,重新打开刚才的文件,先打开主函数.cpp,然后编译运行,打开Fileview,其中有一个external dependencies,把头文件.h,和操作函数.cpp添加到这里,这样再编译运行主函数.cpp,程序运行成功!

偶遇到的应该是CSDN里提到的第一种情况,可是偶是用某人博客的解决方案一解决问题的,学习了。。。

 

 

posted on 2010-07-01 09:57  二地主  阅读(781)  评论(0编辑  收藏  举报