Tag Archives: error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup

error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup

1、 Problem Description:

error LNK2019: unresolved external symbol _ WinMain@16 referenced in function ___ tmainCRTStartup

2、 The causes are as follows

1. You build a console program with VC, its entry function should be main, and you use WinMain

2. You use VC to open a. C /. Cpp file, and then directly compile this file, which uses winmian instead of main as the entry function. VC at this time the default setting is for the console program.

3: Solution:

1. Using the main function

Project-> Properties-> C/C++-> Preprocessor-> Preprocessor definitions delete_ Windows, add_ CONSOLE

Project-> Properties-> Linker-> System-> Select console (/ subsystem: console)
for subsystem

2. Using WinMain function

Project-> Properties-> C/C++-> Preprocessor-> Preprocessor definitions delete_ Console, adding_ WINDOWS

Project-> Properties-> Linker-> System-> Select windows (/ subsystem: Windows) for subsystem

(VS2010 test environment)

After the operating system loads the application program, it completes the initialization work and goes to the entry point of the program for execution. The default entry point of the program is actually set by the linker, and different linkers choose different entry functions< in VC + +, the entry function set by the linker to the console program is maincrtstartup, which calls the main function written by yourself
the entry function for GUI program is winmaincrtstartup, which calls WinMain function written by yourself

the specific entry point is determined by the connector’s/subsystem: option parameter, which tells the operating system how to run the compiled. EXE file
you can specify four methods: “console | windows | national | POSIX”
if the value of this option parameter is “windows”, it means that the application does not need console when it runs. Please refer to MSDN library for detailed description of connector parameter options. The following four combinations can realize the mixed mode of console and windows, which can achieve the effect of not popping up DOS window, and also can output printf information to the console in Windows program

#pragma comment( linker, "/subsystem:windows /entry:WinMainCRTStartup" )
#pragma comment( linker, "/subsystem:windows /entry:mainCRTStartup" )

#pragma comment( linker, "/subsystem:console /entry:mainCRTStartup" )
#pragma comment( linker, "/subsystem:console /entry:WinMainCRTStartup" )


int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR     lpCmdLine,
int       nCmdShow)
{
     // ... ...
}

int main(void)
{
     // ... ...
}