0

I have just started an online course on C++ using MS Visual Studio 2019 community Edition Here's the program:

// Program 1_1
// Our first program!
#include <iostream>
using namespace std;

int main()
{
cout << "Hello, World!" << endl;
system("pause");
}`

I get the LNK2019 error - unresolved external symbol _main referenced in function "int__cdecl invoke_main(void)" (?invoke_main@@YAHXZ) I'm running Windows 2010 64 bit professional edition Can anyone help me with this error? Thanks in advance...

Richard JB
  • 21
  • 2
  • @paisanco no it will not help in this case. – n. m. could be an AI Jul 11 '21 at 19:00
  • Please post the full build log, not just the error message. – n. m. could be an AI Jul 11 '21 at 19:01
  • 3
    Program is fine so it must be the project settings. Create a new project in MSVS 2019 and make sure you choose project type __Console App__. Then build and run the project with it's default settings. – Richard Critten Jul 11 '21 at 19:12
  • 1
    Just to expand on the comment from @RichardCritten: Windows has this weird ting that GUI applications has typically `WinMain` as entry function, while console applications has `main` as entry function. – HAL9000 Jul 11 '21 at 21:05
  • If you want to have a console window and not have to create a GUI window, then you need to make sure you choose a "Console" project type and not a "Windows" project type. A console app has access to standard input and output via the console window that is automatically created. Have you ever noticed that when you start a normal windows GUI app it doesn't pop up a console window? If you make a console app then your program will always pop up a console - so the reason you make a normal windows GUI app is so that you don't automatically get a console window when you double click. – Jerry Jeremiah Jul 12 '21 at 01:22
  • I followed Richard C's advice (thanks Richard) & created a Solution choosing the project type **Console App**. When I had done that, it had a Hello World example that I could run just fine. I closed that file then created my own. When I ran Debug on it, it always debugged the original example, not my code. I closed the solution & re-opened it having only my code open. When I debugged it, it still ran the original example. I do not understand why. Can anyone help? – Richard JB Jul 14 '21 at 21:04

1 Answers1

0

This complies to me if I remove the "`"

There are a few advices here for this issue: Error LNK2019 unresolved external symbol _main referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ)

BK.
  • 1
  • 2
  • 1
    The "`" is one of SO's formatting characters (used to quote code) and is a simple typo. If you think the link is an exact match then flag the post as a duplicate. – Richard Critten Jul 11 '21 at 20:13
  • Maybe it's not exactly the same but I think it suggests that it's a Linker setup issue. – BK. Jul 11 '21 at 20:40