1 2 3 4 5 6 7 8 9 10 11 12 13 | #include <windows.h> int CALLBACK WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ); void foo(void) { } |
1 2 3 4 5 6 | 1>------ Build started: Project: intro_c, Configuration: Debug Win32 ------ 1>Source.cpp 1>MSVCRTD.lib(exe_winmain.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ) 1>C:\Users\HP\source\repos\intro_c\Debug\intro_c.exe : fatal error LNK1120: 1 unresolved externals 1>Done building project "intro_c.vcxproj" -- FAILED. ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== |
1 | <iostream> |
1 2 3 4 5 6 7 8 9 10 | int CALLBACK WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { /// .. your code goes here } |
Check your project config.
Right-click the project -> Properties -> Linker -> System -> SubSystem.
You probably want that to be set to Windows (/SUBSYSTEM:WINDOWS)
=== tried that, worked for me, VS 2017; got my answer from https://stackoverflow.com/questions/49246136/unresolved-external-int-cdecl-invoke-mainvoid-after-vs2017-15-6-1-update
Linker subsystem is not the problem here. The problem was that there is no definition provided for WinMain, only declaration.
indeed, from the message >>_WinMain@16 referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ)
it seems like they are trying to use invoke_main (tho it’s a guess) which is for console applications
all in all, op and i get that message when we followed day 1 cuz we chose console application, we should’ve chosen the windows desktop application (corresponding to win32 app in the video)
No, that's wrong - they are not calling invoke_main. invoke_main
is MSVC runtime internal function that calls either [w]main or [w]WinMain depending on subsystem you set. It is trying to call WinMain because subsystem is already set to WinMain.
If you would create CONSOLE subsystem project and not provide main function, then you would get different error message - about unresolved external symbol main
referenced in invoke_main
function.
But because error message says that invoke_main
is referencing unresolved WinMain
symbol that 100% means subsystem is already set to WINDOWS.