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: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
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
Dev C++ Undefined Reference To Winmain
![Winmain 16 Dev-c++ Winmain 16 Dev-c++](https://image.slidesharecdn.com/manualdevc-140410150352-phpapp02/95/manual-dev-c-17-638.jpg?cb=1397142440)
![Dev-c++ Dev-c++](https://windows-cdn.softpedia.com/screenshots/Windows-Portable-Applications-Dev-C-Portable_14.png)
Undefined Reference To Winmain Dev C++
Recommend:c - undefined reference to `SDLInit' (undefined reference to `WinMain@16' collect2.exe: error: ld returned 1 exit status) an't find it. I'm using clion ide and mingw. The WinMain function that is missing from your code is the 'main' function that is expected from a GUI Win32 application. If you select 'console' application, it should be looking for the 'main' function, which I presume you have defined in your 'main.c' file. Undefined reference to `WinMain@16' - Error; Dev C linker errors, undefined.