The following error occurs when unresolved external symbol _ main is searched:
When creating an MFC 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.ProgramPortal setting error, prompt:
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 "Link" property 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