Add user32.lib
to the command: it's an import library for user32.dll
, which is linked in by default by g++, but not by Visual C++.
In general, just check the documentation of whatever function the linker protests about.
Note that you do not need to use that non-standard Microsoft monstrosity WinMain
.
Instead just use standard C++ main
.
Then with Microsoft's linker, if you want a GUI subsystem executable add option /entry:mainCRTStartup
.
Minimal C++03 example:
#define UNICODE
#include <windows.h>
int main()
{
MessageBox( 0, L"Hello, world!", L"My app:", MB_SETFOREGROUND );
}
Building from command line with Visual C++ 12.0 as GUI subsystem executable:
[D:\dev\test] > set cl & set link CL=/EHsc /GR /FI"iso646.h" /Zc:strictStrings /we4627 /we4927 /wd4351 /W4 /D"_CRT_SECURE_NO_WARNINGS" /nologo LINK=/entry:mainCRTStartup /nologo [D:\dev\test] > cl winhello.cpp /Fe"hello" /link /subsystem:windows user32.lib winhello.cpp