0

I've been trying to set up SDL2 with MinGW, but I've encountered this error repeatedly:

c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../libmingw32.a(main.o):(.text.startup+0xa0): undefined reference to `WinMain@16'

I have tried adding #define SDL_HANDLED_MAIN to the top of main.cpp, and it does work, however I would like to know how I could get this running using SDL's system, and not bypassing it.

Linkers (in order): -lmingw32 -lSDL2main -lSDL2 -lSDL2_image

Code:

#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>

#include <iostream>

int main(int argc, char **)
{
    std::cout << "Hello world!" << std::endl;
    std::cin.get();
    return 0;
}
StaticBits
  • 1
  • 1
  • 3
  • 1
    The linked post addresses this, in the "undefined reference to WinMain only" section. Unrelated to the question, you should update your compiler, GCC 6 is five years old... – HolyBlackCat Nov 21 '21 at 19:10
  • 1
    This question should help with that: [https://stackoverflow.com/questions/30069830/how-to-install-mingw-w64-and-msys2](https://stackoverflow.com/questions/30069830/how-to-install-mingw-w64-and-msys2) – drescherjm Nov 21 '21 at 19:15
  • This might be helpful: [I get "Undefined reference to 'WinMain@16'"](https://wiki.libsdl.org/FAQWindows#i_get_undefined_reference_to_winmain16) – Ranoiaetep Nov 21 '21 at 20:17

0 Answers0