Reputation: 650
This is the only code I have:
#include <windows.h>
int APIENTRY wWinMain(
_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance,
_In_ LPWSTR pCmdLine,
_In_ int nCmdShow)
{
OutputDebugStringA("Hello\n");
return 0;
}
The wWinMain function with the exact same signature works in a separate project I created with the "Windows Desktop Application" (or something) template.
However I am getting a LNK2019 with the message:
unresolved external symbol _main referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ)
coming from MSVCRTD.lib(exe_main.obj)
I am using Visual Studio 2019 Community Edition with MSVC 2019 on Windows 10. I created an "Empty Project" and only have a "main.cpp" file in the "Source Files" directory.
Can anyone help me try to diagnose what may be going wrong here? I am having no luck reading msdn/searching the web for the solution, it is very frustrating as I am just trying to get off the ground here.
Thank you.
Upvotes: 0
Views: 1195
Reputation: 85481
Set Subsystem to Windows in linker settings (for all configurations and targets).
Visual Studio can compile for different Windows subsystems, each requiring its own program entrypoint. An error saying "_main not found
" suggests your subsystem is set to Console, since the linker is looking for a main()
function.
If you have a WinMain()
entrypoint (or wWinMain()
for Unicode mode), it means you're targeting the Windows subsystem.
Upvotes: 2