undefined reference to ‘WinMain@16’

Phenomenon

For a C project, there is no problem when compiling in 64 bit mode. If you switch to 32-bit mode, you will report an error

undefined reference to [‘ WinMain@16 ‘](mailto:’ WinMain@16 ‘)

Why

First, add the original code:

#include <windows.h>

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
	ShellExecute(NULL,"open","taskkill"," /F /IM nginx.exe",NULL,SW_HIDE);
	ShellExecute(NULL,"open","taskkill"," /F /IM php-cgi.exe",NULL,SW_HIDE);
	ShellExecute(NULL,"open","taskkill"," /F /IM php.exe",NULL,SW_HIDE);
	ShellExecute(NULL,"open","taskkill"," /F /IM BeyondClass.exe",NULL,SW_HIDE);
	return 0;
}

According to the error prompt and the information found on the Internet, it is said that this code does not have the main() function

Solution

Add a main function to the code:

#include <windows.h>

int main()
{
	ShellExecute(NULL,"open","taskkill"," /F /IM nginx.exe",NULL,SW_HIDE);
	ShellExecute(NULL,"open","taskkill"," /F /IM php-cgi.exe",NULL,SW_HIDE);
	ShellExecute(NULL,"open","taskkill"," /F /IM php.exe",NULL,SW_HIDE);
	ShellExecute(NULL,"open","taskkill"," /F /IM BeyondClass.exe",NULL,SW_HIDE);
	return 0;
} 
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
	main();
	return 0;
}

Compile again, OK, the problem is solved

Similar Posts: