Undefined Reference to 'WinMain@16'

As the beatles once sang, "help, I need somebody, Help, not just anybody, Help, you know I need someone, HELP".

I'm trying to break my programming virginity with the simple and basic Hello World program but straight from the outset, computer says no.

A few basic's
> Operating system is Windows 10
> Complier is mingGW
> program is written in notepad and saved as a .cpp file
> typing C++ in DOS returns "C++: Fatal error: no input files" - so I know the compiler has installed correctly

I've copied the program from a C++ book I purchase so I'm confident it correct. However, when I go to DOS and type in C++ hello.cpp the below error appears.

I tried to do a bit of digging around and thought it was a linker problem that's common with windows 10 where windows looks for Winmain to start a program rather than Main. So with this in mind, from DOS, I tried c++ -mwindows -o hello.exe hello.cpp (as -mwindows is supposed to include the extra steps). But this did not work and the same error was received.

I also thought it may be a problem with the compiler so I installed Dev C++ IDE and tried it on there but I got roughly the same error.

minGW Error:
c:/mingw/bin/../lib/gcc/mingw32/5.3.0/../../..libmingw32.a(main.o):(.text.startup+0xa0): Undefined reference to 'WinMain@16"
Collect2.exe: error: 1d returned 1 exit status.


Dev C++ error:
- C++ Compiler: C:\Users\Public\Dev-Cpp\MinGW64\bin\g++.exe
- Command: g++.exe "C:\Users\greg_\MyPrograms\Hello.cpp" -o "C:\Users\greg_\MyPrograms\Hello.exe" -I"C:\Users\Public\Dev-Cpp\MinGW64\include" -I"C:\Users\Public\Dev-Cpp\MinGW64\x86_64-w64-mingw32\include" -I"C:\Users\Public\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include" -I"C:\Users\Public\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++" -L"C:\Users\Public\Dev-Cpp\MinGW64\lib" -L"C:\Users\Public\Dev-Cpp\MinGW64\x86_64-w64-mingw32\lib" -static-libgcc
C:\Users\Public\Dev-Cpp\MinGW64\x86_64-w64-mingw32\lib/libmingw32.a(lib64_libmingw32_a-crt0_c.o): In function `main':
C:/crossdev/src/mingw-w64-v3-git/mingw-w64-crt/crt/crt0_c.c:18: undefined reference to `WinMain'
collect2.exe: error: ld returned 1 exit status



Program:
#include <iostream>
using namespace std;

//A C++ Program to output a greeting

int Main()
{
cout<<"Hello World!"<<endl;
return 0;
}

Is anyone able to advise please?

Thank you
C++ is case-sensitive. The main() function must not be capitalized.
It seems you have created a Windows app instead of a console app.
A windows app needs a WinMain function which you don't have.
Try to create a new console project and copy your code into it. As Peter87 said main must be lower case.
Hi

Thank you both for your assistance with this. Changing the m to lowercase looks to have done the trick.

I've now managed to say hello to the world using minGW as well as Dev C++

Thank you again
Topic archived. No new replies allowed.