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?

4
  • 1
    Is the issue happening regardless of the selected configuration (Debug/Release) and architecture (x86/x64)? Mar 12, 2018 at 23:54
  • I am using several other libraries, and I have not setup Release versions nor Debug x86 architecture. I only have Debug x64.
    – Velchivz
    Mar 13, 2018 at 0:07
  • What's the file name including your main function? Is it added in your vsproject?
    – ravin.wang
    Mar 13, 2018 at 0:40
  • It is added. I tried excluding and include again. Issue is still there.
    – Velchivz
    Mar 13, 2018 at 0:54

7 Answers 7

8

Check your project config.

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

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

2
  • 7
    Tried this, issue still remains.
    – Velchivz
    Mar 13, 2018 at 0:38
  • 1
    This did the trick. It must be because I chose an empty project. It was set to console application by default. Dec 3, 2018 at 16:55
3

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

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.

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
1
  • 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, 2018 at 0: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.
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.

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)

1
  • How is #include <tchar.h> helping to find main()? Jan 17 at 13:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.