Sep 19, 2013 WinAPI programs have a different entry point called WinMain. If you are using the regular main, you probably meant to have a console program. I'm not exactly sure where this setting is in C::B. But go in your project settings and look around for an option in the linker settings that specifies the build target, or what kind of program is. Undefined reference to `WinMain@16' thomson101. Hi, i am super noob in c programming i actually don't have a programming question yet, but a lot of compiler.
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:UsersPublicDev-CppMinGW64bing++.exe
- Command: g++.exe 'C:Usersgreg_MyProgramsHello.cpp' -o 'C:Usersgreg_MyProgramsHello.exe' -I'C:UsersPublicDev-CppMinGW64include' -I'C:UsersPublicDev-CppMinGW64x86_64-w64-mingw32include' -I'C:UsersPublicDev-CppMinGW64libgccx86_64-w64-mingw324.9.2include' -I'C:UsersPublicDev-CppMinGW64libgccx86_64-w64-mingw324.9.2includec++' -L'C:UsersPublicDev-CppMinGW64lib' -L'C:UsersPublicDev-CppMinGW64x86_64-w64-mingw32lib' -static-libgcc
C:UsersPublicDev-CppMinGW64x86_64-w64-mingw32lib/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
Undefined Reference To Winmain 16 Mingw
You do indeed lack a WinMain function anywhere in that code. If memory serves me well, WinMain is the entry point for a Win32 GUI app. I am assuming your IDE asked you for a 'project type' of some sort, and you asked for a Windows app instead of a Console one.