3

I hope someone can help/guide me here. I had a working application, but today I keep getting the following error:

LNK2019 unresolved external symbol main referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ)

The only thing that changed was that I updated VS2017 15.5.4 to VS2017 15.6.1 (latest). I been reading here and there, and I believe somewhere some setting may have changed and now the program is failing to "see" the main function. For the record, I did try this code in my laptop which still has VS2017 15.5.4 and ran without any issues. Any idea what it may be?

melpomene
  • 84,125
  • 8
  • 85
  • 148
Velchivz
  • 99
  • 1
  • 1
  • 8

7 Answers7

8

Check your project config.

Right-click the project -> Properties -> Linker -> System -> SubSystem.

You probably want that to be set to Windows (/SUBSYSTEM:WINDOWS)

Kirill Shlenskiy
  • 9,367
  • 27
  • 39
3

I couldn't find a fix to it. I had to make a new project and move everything there.

Velchivz
  • 99
  • 1
  • 1
  • 8
3

I got exactly this error when I was linking against the SDL2 libraries, but only included SDL2.lib and forgot SDL2main.lib. The error appeared as soon as I included sdl.h in my source code, without directly calling any SDL functions in the code. I was confused because of the reference to invoke_main(void) and thus didn't suspect that any external libraries were missing when linking.

Bjorn
  • 1,090
  • 8
  • 12
0

Check these points:

  1. Is the .c/.cpp file including main function added into your vsproject file?
  2. Make sure "Configuration -> C/C++ -> Advance -> Calling Conversion -> __cdelc(/Gd)" to be selected
ravin.wang
  • 1,122
  • 1
  • 9
  • 26
  • 1) The file with main function is added to vsproject file (this code works on older version of VS2017, I also tried to exclude then include). 2) It is selected to that option. Issue still remain. – Velchivz Mar 13 '18 at 00:53
0

This worked for me:

  1. In the solution explorer, Right click the file containing main() function and exclude it from project.
  2. Right click project and select add existing item and add the excluded file back to project.
  3. Clean the project and build.
Sumant
  • 3
  • 2
  • 6
0

If you are using CMake project - most likely you have CMakeLists.txt somewhere in your project that calls add_executable(MY_TARGET my_source.cpp) and this target's source file's name is different.

That is why this error occurred in my case.

vocasle
  • 799
  • 8
  • 11
0

Try including tchar.h header file, along with windows.h:

#include <windows.h>
#include <tchar.h>

Also, the linker subsystem property should be Windows (/SUBSYSTEM:WINDOWS)