error LNK2019: Unresolved external symbol WinMain(vs2019)

created at 11-16-2021 views: 43

1. description


MSVCRTD.lib(crtexew.obj): error LNK2019: Unresolved external symbol _WinMain@16, this symbol is referenced in the function ___tmainCRTStartup
Debug\jk.exe: fatal error LNK1120: 1 unresolved external command
error LNK2001: unresolved external symbol _WinMain@16
debug/main.exe: fatal error LNK 1120:1 unresolved externals
error executing link.exe;

2. Reasons and solutions

The real reason for this problem is that the proper program entry function cannot be found when the C language is running.

Under normal circumstances, if it is a windows program, then WinMain is the entry function, and the new project in VS2008 is win32 project

If it is a DOS console program, then `main` is the entry function, and the new project in VS2008 is win32 console application

And if the entry function is not specified properly, obviously it will report an error if it cannot find the matching function when the c language is running.

Modify the settings to suit your needs

If it is a windows program:

  1. Select Project->Properties in the menu, and the Property Pages window will pop up
  2. Select in the left column in turn: Configuration Properties->C/C++->Preprocessor, then delete _CONSOLE from the corresponding item of Preprocessor Definitions in the right column, and add _WINDOWS.
  3. In the left column, select in turn: Configuration Properties->Linker->System, and then the corresponding item of SubSystem in the right column is changed to Windows(/SUBSYSTEM:WINDOWS)

If it is a console program:

  1. Select Project->Properties from the menu, and the Property Pages window will pop up
  2. In the left column, select in turn: Configuration Properties->C/C++->Preprocessor, then delete _WINDOWS from the item corresponding to Preprocessor Definitions in the right column, and add _CONSOLE.
  3. In the left column, select in turn: Configuration Properties->Linker->System, and then the corresponding item of SubSystem in the right column is changed to CONSOLE(/SUBSYSTEM:CONSOLE)
created at:11-16-2021
edited at: 11-16-2021: