'undefined reference to `WinMain@16' while compiling

So I just installed VS code and was trying to run a code when this came up. Searched through the web for a relevant answer but none worked.

Here is a more detailed output in the console:

cd "f:\" && g++ testing.cpp -o testing && "f:\"testing
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../libmingw32.a(main.o):(.text.startup+0xa0): undefined reference to `WinMain@16'
collect2.exe: error: ld returned 1 exit status,

By the way I am using code-runner to run that single file. I have MinGW path all set up( don't know if that even matters). Please, someone help.here is what it looks like



Solution 1:[1]

The code runner does not save your code before running it. You can see the commands it executes in the error snippet you have added

cd "f:\" && g++ testing.cpp -o testing && "f:\"testing

So make sure you save your code before running it.This happened with me and I wasted quite some time.Hope this helps.

Solution 2:[2]

save your single file and then complie successfully, i had the same question as yours and solved by this way.

Solution 3:[3]

I had the same problem and this worked for me on VS Code. Go to

File -> Preferences -> Settings -> Run Code Configuration

And check the Save all files before run.

Solution 4:[4]

If it is cpp file, you should have a main function in your file to avoid this error.

Solution 5:[5]

You need to save the program before executing...That's the most probable problem. If the problem still persists then that means your Mingw folder got corrupted and you need to reinstall it . It won't take long just 3-4min max. . . . In case you want the link !! https://sourceforge.net/projects/mingw/ . . . P.S. --> try clearing the path again in the environment variable!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Raghav
Solution 2 junpfeng
Solution 3 António Ribeiro
Solution 4 Sepehr Saeidi Farzad
Solution 5 Nikhil Verma