0

I'm trying to create a basic window with c++ by following this guide but it isn't working. The errors i get are unresolved external symbol_main referenced in function "int_cdecl invoke_main (void)" (?invoke_main@@YAHXZ) at line 1 and 1 unresolved external at line 1. The code is in the guide, and I used exactly what is in there, even copy and pasting to see if I just made a typo, but it doesn't work. I also made sure i have the latest versions of Visual Studio and Windows SDK.

walid barakat
  • 455
  • 1
  • 6
  • 17
  • C++ doesn't have "windows" or any kind of GUI functionality. What framework or library are you using? On what platform? And please take some time to read [the help pages](http://stackoverflow.com/help), take the SO [tour], read [ask], as well as [this question checklist](https://codeblog.jonskeet.uk/2012/11/24/stack-overflow-question-checklist/). Lastly please [edit] your question to show us a [mcve] of your code. – Some programmer dude Apr 07 '20 at 01:26
  • Are you building a windows or a console application (it'll be in your project settings)? I haven't used Windows or Visual Studio in years, so my terminology might be wrong. – Stephen Newell Apr 07 '20 at 01:27
  • Related: https://stackoverflow.com/questions/7316433/difference-between-console-subsystemconsole-and-windows-subsystemwindows – Jerry Jeremiah Apr 07 '20 at 01:40

2 Answers2

1

You need to set SubSystem to "Windows (/SUBSYSTEM:WINDOWS)" instead of "Console (/SUBSYSTEM:CONSOLE)".

CONSOLE programs use _main() as their entry point (which does some setup and then calls your main() function)

WINDOWS programs use WinMain or wWinMain as their entry point (depending on whether they are being compile for ANSI or UNICODE respectively).

Your guide had you make a wWinMain function so you need to make sure the compiler settings are set for a WINDOWS subsystem and UNICODE encoding.

Have a look at the instructions here: https://codeyarns.com/2010/12/02/visual-c-windows-and-console-subsystems/

Jerry Jeremiah
  • 9,045
  • 2
  • 23
  • 32
DevO
  • 365
  • 1
  • 8
1

An example works just fine. I opened a solution file provided there. If you just trying to compile the program using only compiler and main.cpp make sure that your environment set up correctly. Don't just copy-paste it. Download all three files there https://github.com/microsoft/Windows-classic-samples/tree/master/Samples/Win7Samples/begin/LearnWin32/HelloWorld/cpp and open HelloWorld.sln in VisualStudio.

And as others said, set SubSystem properly:

enter image description here

user3417815
  • 615
  • 6
  • 28