-1

I am taking a course in c++ and I've copied the code and done exactly the same as the tutor in the course did in the lecture, however when I do so I get a long error "...undefined reference to `WinMain'" and I don't know what to do.

I am using Eclipse Neon on Windows 10 (and Cygwin, I don't know if it's relevant) and this is my code:

`

#include <iostream>
#include <SDL.h>
using namespace std;

int main() {

cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
return 0;

} ` The code works and runs without the "#include ", but when I add this line of code the error pops up when I run it (so I guess that's where the problem is). When the tutor in the course run this code it works and prints out the text correctly. Can someone please tell me how I get rid of this error and get this simple program to run?

Tob237
  • 291
  • 1
  • 5
  • 15

1 Answers1

2

https://wiki.libsdl.org/FAQWindows#I_get_.22Undefined_reference_to_.27WinMain.4016.27.22

I get "Undefined reference to 'WinMain@16'"

Under Visual C++, you need to link with SDL2main.lib. Under the gcc build environments including Dev-C++, you need to link with the output of "sdl-config --libs", which is usually: -lmingw32 -lSDL2main -lSDL2 -mwindows

vz0
  • 32,345
  • 7
  • 44
  • 77