2022年VC编译常见错误 .pdf
《2022年VC编译常见错误 .pdf》由会员分享,可在线阅读,更多相关《2022年VC编译常见错误 .pdf(10页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、VC 编译常见错误 - - 1、Fatal Error C1010 unexpected end of file while looking for precompiled header directive 这一般是由于使用了参数/Yustdafx.h ,意思是在每个文件中都应该使用#include来包含这个头文件。一般改正,就是在每个。CPP 文件中包含这个文件就可以。2、LNK2001 on _beginthreadex and _endthreadex 这是一个非常常见的链接错误。原因是由于在VC3 。0 以后所有的MFC 类都是线程安全的,在MFC 类库中使用了 Thread Loca
2、l Storage (TLS)提供预处理的数据。 因此如果程序中包含了stfafx.h 头文件或者使用了, MFC 类库中的类就会使用MSVCRTx0.DLL 来进行链接。改正方法如下:On Visual C 2.x, 5.0, and 6.0: Select the Project menu, and then continue Steps 2 through 5 below. On Visual C 4.x: Select the Build menu. Select the Settings. option. Select the C/C+ tab. Select Code Genera
3、tion on the Category list box. Finally, make a selection other than Single-Threaded on the Use Run Time Library list box. 如果使用了 Multithreaded using DLL方式还要求在预处理符号中加上_AFXDLL 符号 . 还在 LIBC 。LIB 是 C Runtime的静态链接库。MSVCRTx0.DLL 是 C Runtime的动态链接库。如果程序中包含了任何MFC 代码 ,或者编译使用了/MT 选项 ,都要求使用多线程库。为什么在程序中包含了StdAfx.
4、h 文件也会出现这个连接错误呢?是由于在StdAfx.h 中使用了 MFC类,并且重载了new 等操作符,如果在程序中使用了NEW 等就会出现链接错误。1、Fatal Error C1010 unexpected end of file while looking for precompiled header directive 这一般是由于使用了参数/Yustdafx.h ,意思是在每个文件中都应该使用#include来包含这个头文件。一般改正,就是在每个。CPP 文件中包含这个文件就可以。2、LNK2001 on _beginthreadex and _endthreadex 这是一个非常
5、常见的链接错误。原因是由于在VC3 。0 以后所有的MFC 类都是线程安全的,在MFC 类库中使用了 Thread Local Storage (TLS)提供预处理的数据。 因此如果程序中包含了stfafx.h 头文件或者使用了, MFC 类库中的类就会使用MSVCRTx0.DLL 来进行链接。改正方法如下:On Visual C 2.x, 5.0, and 6.0: Select the Project menu, and then continue Steps 2 through 5 below. On Visual C 4.x: Select the Build menu. Select
6、 the Settings. option. Select the C/C+ tab. Select Code Generation on the Category list box. Finally, make a selection other than Single-Threaded on the Use Run Time Library list box. 如果使用了 Multithreaded using DLL方式还要求在预处理符号中加上_AFXDLL 符号 . 还在 LIBC 。LIB 是 C Runtime的静态链接库。MSVCRTx0.DLL 是 C Runtime的动态链接
7、库。如果程序中包含了任何MFC 代码 ,或者编译使用了/MT 选项 ,都要求使用多线程库。名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 1 页,共 10 页 - - - - - - - - - 为什么在程序中包含了StdAfx.h 文件也会出现这个连接错误呢?是由于在StdAfx.h 中使用了 MFC类,并且重载了new 等操作符,如果在程序中使用了NEW 等就会出现链接错误。http:/ C+ Error Messages Visual C+ Error Messages Thi
8、s page contains a listing of difficult to diagnose error messages and possible fixes. I havent taught a programming class that uses Visual C+ in several years so this list is probably out of date by now. It was valid for Microsoft Visual C+ version 6.0 service pack 3. C1001: INTERNAL COMPILER ERROR
9、(compiler file msc1.cpp, line 1786) Please choose the Technical Support command on the Visual C+ Help menu, or open the Technical Support help file for more information This error results from leaving off the parentheses immediately following the function name in a function header. To correct the er
10、ror simply add () to the end of the function name. C1010: unexpected end of file while looking for precompiled header directive If your project is an MFC AppWizard created project then this error results from not #including StdAfx.h as the first i nclude statement (before any other i ncludes, data d
11、eclarations, or executable program code). C1083: Cannot open precompiled header file: Debug/.pch: No such file or directory This error results from a missing file - the compiled version of StdAfx.cpp. Visual C+ does a poor job of keeping track of this file and frequently forgets how to build it. Thi
12、s problem often occurs after restoring a saved workspace from diskette without the Debug directory. To fix the error select StdAfx.cpp from the workspace file list them choose Compile from the Build menu. If that doesnt work the go to Project - Settings, select the C/C+ tab, and click the radio butt
13、on labeled Create Precompiled Headers. C2001: newline in constant This error is usually caused by a string or character constant that is missing its closing or symbol. C2065: : undeclared identifier If this error occurs in one of your member functions then it is generally the result of forgetting th
14、e class scope operator in front of the function name in your .cpp file. C2143: syntax error : missing ; before PCH creation point Check each of the i nclude files to ensure that the closing brace of each class declaration is followed by a semicolon. C2143: syntax error : missing ; before * If this e
15、rror is followed by two C2501 errors then the problem is an undeclared class name within a pointer declaration. For example, the declaration: CClass *pObject; will generate the above error message followed by a C2501 error message for CClass and another C2501 message for pObject. The problem is that
16、 the compiler isnt recognizing CClass as a valid class/type name. To correct the problem add a i nclude of the file containing the declaration of CClass (e.g., i nclude CClass.h) C2447: missing function header (old-style formal list?) This error usually results from a missing or use of a ; instead o
17、f a following the parameter list of a function header. 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 2 页,共 10 页 - - - - - - - - - C2511: : overloaded member function not found in This error results from a mismatch in the parameter list of a member function declarati
18、on (.h file) and definition (.ccp file). Check the forward declaration of the function in the .h file and its definition in the .cpp file and ensure that the number of parameters and the type of each parameter match exactly.C2512: : no appropriate default constructor available This error usually occ
19、urs when you implement the constructor function of a derived class and forget to include parameter passing to the base class constructor function. For example assume that CDerived is derived from CBase and that the CBase constructor function requires one parameter (e.g., int A). If you define the CD
20、erived constructor function as: CDerived:CDerived(int A, int B) . the compiler will issue the above error message on the line containing the function header of CDerived:CDerived() because you havent provided instructions for routing the parameter A to CBase:CBase(). Because you didnt provide instruc
21、tions the compiler assumes that CBase:CBase() requires no arguments and it complains because no version of CBase:CBase() has been defined that accepts zero arguments. If you intended to provide a version of CBase:CBase() that requires no arguments then the error message indicates that you forgot to
22、declare that function in your base class declaration (e.g., in CBase.h). If CBase:CBase() does require one or more arguments then you must correct the problem by including explicit instructions for passing parameters from the derived class constructor function to the base class constructor function.
23、 The correction for the example above is: CDerived:CDerived(int A, int B) : CBase(A) . C2556: : overloaded functions only differ by return typeC2371: : redefinition; different basic types These errors usually result from a mismatch of function type between a .h and .cpp file. Check the forward decla
24、ration of the function in the .h file and its definition in the .cpp file and make the function return type identical in both files. C2601: : local function definitions are illegal This error results from defining one function inside the body of another function. It usually means that you omitted on
25、e or more symbols in the function just before the function named in the error message. C2653: : is not a class or namespace name This error usually results from not having i nclude StdAfx.h as the first i nclude statement in your class.cpp file. It can also occur if your class definition is in a .h
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 2022年VC编译常见错误 2022 VC 编译 常见 错误
限制150内