VC錯誤提示(ZZ)

來源:互聯網
上載者:User
在建立項目時, 不使用MFC AppWizard嚮導, 如果沒有設定好項目參數, 就會在編譯時間產生很多串連錯誤, 如error LNK2001錯誤, 典型的錯誤提示有:
libcmtd.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
msvcrtd.lib(crtexew.obj) : error LNK2001: unresolved external symbol _WinMain@16
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __beginthreadex
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __endthreadex

下面介紹解決的方法:
1. Windows子系統設定錯誤, 提示:
libcmtd.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Windows項目要使用Windows子系統, 而不是Console, 可以這樣設定:
[Project] --> [Settings] --> 選擇"Link"屬性頁面,
在Project Options中將/subsystem:console改成/subsystem:windows

2. Console子系統設定錯誤, 提示:
LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
控制台項目要使用Console子系統, 而不是Windows, 設定:
[Project] --> [Settings] --> 選擇"Link"屬性頁面,
在Project Options中將/subsystem:windows改成/subsystem:console

3. 程式入口設定錯誤, 提示:
msvcrtd.lib(crtexew.obj) : error LNK2001: unresolved external symbol _WinMain@16
通常, MFC項目的程式入口函數是WinMain, 如果編譯項目的Unicode版本, 程式入口必須改為wWinMainCRTStartup, 所以需要重新設定程式入口:
[Project] --> [Settings] --> 選擇"C/C++"屬性頁面,
在Category中選擇Output,
再在Entry-point symbol中填入wWinMainCRTStartup, 即可

4. 線程執行階段程式庫設定錯誤, 提示:
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __beginthreadex
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __endthreadex
這是因為MFC要使用多線程時庫, 需要更改設定:
[Project] --> [Settings] --> 選擇"C/C++"屬性頁面,
在Category中選擇Code Generation,
再在Use run-time library中選擇Debug Multithreaded或者multithreaded
其中,
Single-Threaded 單線程靜態連結庫(release版本)
Multithreaded 多線程靜態連結庫(release版本)
multithreaded DLL 多線程動態連結程式庫(release版本)
Debug Single-Threaded 單線程靜態連結庫(debug版本)
Debug Multithreaded 多線程靜態連結庫(debug版本)
Debug Multithreaded DLL 多線程動態連結程式庫(debug版本)
單線程: 不需要多線程調用時, 多用在DOS環境下
多線程: 可以並發運行
靜態庫: 直接將庫與程式Link, 可以脫離MFC庫運行
動態庫: 需要相應的DLL動態庫, 程式才能運行
release版本: 正式發布時使用
debug版本: 調試階段使用

VC 6.0“Compiling... ,Error spawning cl.exe”錯誤解決
Posted on 2005-06-03 19:55 k_eckel 閱讀(8862) 評論(100) 編輯 收藏
可能很多人在安裝VC 6.0後有過點擊“Compile”或者“Build”後被出現的“Compiling... ,Error spawning cl.exe”錯誤提示給鬱悶過。很多人的選擇是重裝,實際上這個問題很多情況下是由於路徑設定的問題引起的,“CL.exe”是VC使用真正的編譯器(編譯器),其路徑在“VC根目錄/VC98/Bin”下面,你可以到相應的路徑下找到這個應用程式。
因此問題可以按照以下方法解決:點擊VC“TOOLS(工具)”—>“Option(選擇)”—>“Directories(目錄)”重新設定“Excutable Fils、Include Files、Library Files、Source Files”的路徑。很多情況可能就一個盤符的不同(例如你的VC裝在C,但是這些路徑全部在D),改過來就OK了。

nafxcw.lib(appcore.obj) : error LNK2001: unresolved external symbol ___argv
解決方案:

在Preprocessor中定義_AFXDLL

如果它提示:
fatal error C1189: #error : Please use the /MD switch for _AFXDLL builds

就這樣改:

C/C++->Code Generation->Multithread DLL (即實現/MD選項)

Visual C++ Error MessagesThis page contains a listing of "difficult to diagnose" error messages and possible fixes. I haven't 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 (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 error 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 declarations, or executable program code).

--------------------------------------------------------------------------------

C1083: Cannot open precompiled header file: 'Debug/<Project-Name>.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. This 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 doesn't work the go to Project -> Settings, select the C/C++ tab, and click the radio button 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: '<data-member name>' : undeclared identifier

If this error occurs in one of your member functions then it is generally the result of forgetting the 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 error 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 the compiler isn't 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 of a { following the parameter list of a function header.

--------------------------------------------------------------------------------

C2511: '<function-name>' : overloaded member function not found in '<class-name>'

This error results from a mismatch in the parameter list of a member function declaration (.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: '<constructor-function-name>' : no appropriate default constructor available

This error usually occurs 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 CDerived 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 haven't provided instructions for routing the parameter A to CBase::CBase(). Because you didn't provide instructions 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 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. The correction for the example above is:

CDerived::CDerived(int A, int B) : CBase(A) { ... }

--------------------------------------------------------------------------------

C2556: '<function-name>' : overloaded functions only differ by return type
C2371: '<function-name>' : redefinition; different basic types

These errors usually result from a mismatch of function type between a .h and .cpp file. Check the forward declaration 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: '<function-name>' : local function definitions are illegal

This error results from defining one function inside the body of another function. It usually means that you omitted one or more } symbols in the function just before the function named in the error message.

--------------------------------------------------------------------------------

C2653: '<Class-Name>' : 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 file and you forget to #i nclude that .h file in another file that refers to the class name.

--------------------------------------------------------------------------------

C2661: '<Class-Name>::<Function-Name>' : no overloaded function takes n parameters

This error indicates a mismatch between the parameters used in a function call (e.g., from main.cpp) and the declaration of the function. The function call is passing n parameters and there is no function declaration that uses that number of parameters.

--------------------------------------------------------------------------------

LNK1104: Cannot open file nafxcwd.lib

This error sometimes occurs when a project uses a class from the MFC but the project settings don't explicitly tell the link editor to look in the MFC libraries.

Go to Project --> Settings (Build --> Settings in Visual C++ 4.0). On the General tab check the box that says "Use MFC in a Shared DLL".

--------------------------------------------------------------------------------

LNK1168: cannot open Debug/<Project-Name>.exe for writing

This error occurs when the link editor attempts to write to a .exe file that is currently in use. The .exe file of an executing program is write protected until the program is terminated. Look at the status bar at the bottom of your screen and find the icon representing your executable application. Open the application and exit from it. Then select Build.

--------------------------------------------------------------------------------

LNK2001: unresolved external symbol __endthreadex
LNK2001: unresolved external symbol __beginthreadex

These errors result from using an MFC object or function without telling the link editor to search the MFC libraries.

Go to Project --> Settings (Build --> Settings in Visual C++ 4.0). On the General tab check the box that says "Use MFC in a Shared DLL".

--------------------------------------------------------------------------------

LNK2001: unresolved external symbol _main

Your project doesn't contain a function called main(). The error usually results from forgeting to add main.cpp to the project workspace.

--------------------------------------------------------------------------------

<File>.obj : error LNK2001: unresolved external symbol "public: void __thiscall <Class1>::<Function1>(<Type>)"

This a generic form of a LNK2001 error where <File>.obj can be any object file in your project and <Class1>::<Function1>(<Type>) can be any function in any class. Substitute the specific <File>, <Class>, <Function>, and <Type> in your message into the instructions below to diagnose and correct the problem.

An LNK2001 error means that the link editor is looking for a compiled function and can't find it. The call to the "missing function" is somewhere in <File>.cpp. Unfortunately, double-clicking on the error message won't take you to the point in <File.cpp> where the function is called but you can search for it with Find or Find In Files. The function the link editor can't find is a member of <Class>, its name is <Function1>, and its return type is <Type>.

There are two common reasons for a LNK2001 error:

The call in <File>.cpp doesn't match the function prototype in <Class>.h and/or the implementation in <Class>.cpp. The mismatch may be in the function name, return type, or number and/or type of parameters. Correction strategies include:
Check that the function name is spelled the same (case sensitive) in all three files (File.cpp, Class.h, and Class.cpp).
Check that the function is actually declared and defined within <Class> - perhaps you defined it as a member of a different class or perhaps you tried to call the function (in <File>.cpp) using an object or object pointer of a different class.
Check that the number and type of parameters in the function implementation (in <Class>.cpp) matches the number and type of parameters declared in the function declaration in <Class>.h.
Check that the number and type of parameters in the function call (in <File>.cpp) matches the number and type of parameters declared in the function header in <Class>.cpp.
The function was never declared or was declared but never defined. To see if either is the case go to the ClassView window of the Workspace view. Click the + next to <Class> and find <Function> in the list of member functions.
If <Function> is NOT in the list then it was never declared or defined - add a declaration to the class declaraion in <Class>.h and implement the function in <Class>.cpp.
If <Function> is in the list then right click on it and select Go To Definition from the pop-up menu. If you get the error message Cannot find definition (implementation) of this function then the function was declared but never defined (implemented). Implement the function to <Class>.cpp.

--------------------------------------------------------------------------------

LNK2005: <some-long-string-of-mostly-garbage> already defined in <name>.lib(<name>.obj)

This error usually results from including a source code file multiple times. If you recognize any of the names in the message then it probably results from multiple inclusion of one of your own header files. Check to be sure that you've used #ifndef/#define/#endif properly your header files. If you don't recognize the name then it's probably multiple inclusion of a system file (e.g., afxwin.h). Make sure that you haven't explicitly included something in main.cpp that is already included in one of your own header files. Also check that you haven't #i ncluded a .cpp file where you should have #i ncluded a .h file.  

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.