0

I'm getting an error in C++ in VsCode. When I try to run this code(It's a very basic code):

#include <iostream>


int main()

{
    std::cout << "Hello World";
    return 0;
}

I'm getting this error:

undefined reference to 'WinMain@16' collect2.exe: error: ld returned 1 exit status

I know there are some solutions for this error in this forum but I still can't get it fixed because I'm new on C++ and I'm trying to learn it. Can someone help me?

Anhedonia
  • 37
  • 1
  • 7

1 Answers1

0

The problem seems to be with the main-function. Try int wmain().

Check up on main-functions in c++ under windows here or here

melk
  • 530
  • 3
  • 9
  • `int wmain()` didn't worked and I still don't know how to solve this problem. Like what I said I'm new on C++ so I really can't understand what are them in the links. I tried to run this code in eclipse and it worked but the problem is I want to use VS code. Any other ideas? – Anhedonia Apr 01 '20 at 16:12
  • Are you sure you're compiling this as a console-application? the main-function for a window-application would look like this: `int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow);` – melk Apr 01 '20 at 16:18
  • @SyntaxError Happy to help ;) – melk Apr 01 '20 at 16:31