SoFunction
Updated on 2025-03-07

The solution to unresolved external symbol _main is prompted

Unresolved external symbol _main searched and found the following reasons
When creating an MFC project, you do not use the MFC AppWizard wizard. If the project parameters are not set, many connection errors will occur during compilation, such as the error LNK2001 error. Typical error prompts are:

() : error LNK2001: unresolved external symbol _main

() : error LNK2001: unresolved external symbol _WinMain@16

() : error LNK2001: unresolved external symbol _WinMain@16

() : error LNK2001: unresolved external symbol __beginthreadex

() : error LNK2001: unresolved external symbol __endthreadex





The solution is described below:

1. Windows subsystem settings are incorrect, prompt:

() : error LNK2001: unresolved external symbol _main

Windows projects need to use the Windows subsystem instead of Console. You can set it like this:

[Project] --> [Settings] --> Select the "Link" property page,

Change /subsystem:console to /subsystem:windows in Project Options





2. Console subsystem setting error, prompt:

() : error LNK2001: unresolved external symbol _WinMain@16

Console project needs to use the Console subsystem, not Windows, set:

[Project] --> [Settings] --> Select the "Link" property page,

Change /subsystem:windows to /subsystem:console in Project Options





3. Program entry setting error, prompt:

() : error LNK2001: unresolved external symbol _WinMain@16

Usually, 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, so the program entry needs to be reset:

[Project] --> [Settings] --> Select the "Link" property page,

Select Output in Category,

Then fill in wWinMainCRTStartup in the Entry-point symbol, just





4. The thread runtime library is set incorrectly, prompt:

() : error LNK2001: unresolved external symbol __beginthreadex

() : error LNK2001: unresolved external symbol __endthreadex

This is because MFC needs to use multithreaded library, settings need to be changed:

[Project] --> [Settings] --> Select the "C/C++" property page,

Select Code Generation in Category,

Then select Debug Multithreaded or multithreaded in Use run-time library

in,

Single-Threaded Single-Threaded static link library (release version)

Multithreaded Multithreaded static link library (release version)

multithreaded DLL multithreaded dynamic link library (release version)

Debug Single-Threaded Single-Threaded Static Link Library (debug version)

Debug Multithreaded Multithreaded static link library (debug version)

Debug Multithreaded DLL Multithreaded Dynamic Link Library (debug version)

Single thread: When multi-threading is not required, it is mostly used in DOS environment

Multithreading: Can be run concurrently

Static library: Directly link the library and program, it can be run without the MFC library

Dynamic library: The corresponding DLL dynamic library is required for the program to run

Release version: Used when officially released

debug version: Used in the debugging stage