When creating a project, the MFC Appwizard wizard is not used. If the project parameters are not set, many connection errors will be generated during compilation, such as error lnk2001. Typical error prompts include:
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
The solution is as follows:
1. Windows subsystem setup error, prompt:
Libcmtd. Lib (crt0.obj): Error lnk2001: unresolved external symbol _ main
For Windows projects, you must use the Windows subsystem instead of the console. You can set it as follows:
[Project] --> [settings] --> select the "Link" property page,
Change/subsystem: console to/subsystem: Windows in project options.
2. the console subsystem settings are incorrect. The following message is displayed:
Libcd. Lib (wincrt0.obj): Error lnk2001: unresolved external symbol _ winmain @ 16
For a console project, use the console subsystem instead of windows. Set:
[Project] --> [settings] --> select the "Link" property page,
Change/subsystem: Windows to/subsystem: console in project options.
3. The program entry settings are incorrect. The prompt is:
Msvcrtd. Lib (crtexew. OBJ): Error lnk2001: unresolved external symbol _ winmain @ 16
Generally, the program entry function of the MFC project is winmain. If the Unicode version of the project is compiled, the program entry must be changed to wwinmaincrtstartup. Therefore, you need to reset the program entry:
[Project] --> [settings] --> select the "C/C ++" attribute page,
In category, select output,
Enter wwinmaincrtstartup in entry-point symbol.
4. When the thread is running, the database settings are incorrect. The prompt is:
Nafxcwd. Lib (thrdcore. OBJ): Error lnk2001: unresolved external symbol _ beginthreadex
Nafxcwd. Lib (thrdcore. OBJ): Error lnk2001: unresolved external symbol _ endthreadex
This is because when MFC uses a multi-threaded library, you need to change the settings:
[Project] --> [settings] --> select the "C/C ++" attribute page,
In category, select code generation,
Select debug multithreaded or multithreaded in the use run-time library.
Where,
Single-threaded single-thread static link library (Release Version)
Multithreaded multi-thread static link library (Release Version)
Multithreaded DLL multi-thread dynamic link library (Release Version)
Debug single-threaded single-thread static link library (debug version)
Debug multithreaded multi-thread static link library (debug version)
Debug multithreaded DLL multi-thread dynamic link library (debug version)
Single thread: When multi-thread calling is not required, it is usually used in DOS environments.
Multithreading: Concurrent Operation
Static Library: link the library directly with the program and run it without the MFC library.
Dynamic library: The corresponding DLL dynamic library is required for the program to run.
Release Version: used for official release
Debug version: used during debugging
VC 6.0 "compiling..., error spawning cl.exe" error solved
Posted on k_eckel read (8862) Comments (100) EDIT favorites
After installing VC 6.0, many people may encounter the "compiling..., error spawning cl.exe" error after clicking "compile" or "build. Compile "is the true compiler used by VC (compile program). Its path is under" VC root directory/vc98/bin ". You can find this application in the corresponding path.
Therefore, you can solve the problem as follows: Click VC "tools"> "option"> "directories (directory) "reset the path of" excutable fils, include files, library files, source files. In many cases, it may be different from a drive letter (for example, if your VC is installed in C, but all these paths are in d). It will be okay if you change it.
Nafxcw. Lib (appcore. OBJ): Error lnk2001: unresolved external symbol ___ argv
Solution:
Define _ afxdll in Preprocessor
If it prompts:
Fatal error c1189: # error: please use the/MD switch for _ afxdll builds
Change it like this:
C/C ++-> code generation-> multithread DLL (Implementation/MD option)
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 direve ve
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 'pobobject '. 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. h file and its definition in. 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 ). if you define the cderived constructor function:
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 struinctions ctions 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 abve is:
Cderived: cderived (int A, int B): cbase (){...}
--------------------------------------------------------------------------------
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. H and. CPP file. check the Forward Declaration of the function in. h file and its definition in. 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. 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. 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 compression sion 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 compression sion of a System File (e.g ., afxwin. h ). make sure that you haven't explicitly encoded something in main. CPP that is already encoded in one of your own header files. also check that you haven't # I ncluded. CPP file where you shoshould have # I ncluded. h file.