Skip to content
Advertisement

How to cross-compile with SDL 2 from Linux for Windows

I tried to compile a simple C++ program that uses SDL 2 with the mingw-w64-g++ compiler on my Arch Linux (64bits).

For this I downloaded SDL2-devel-2.0.4-mingw.tar.gz from here

prog.cpp:

JavaScript

Makefile:

JavaScript

Now making gives the error:

JavaScript

Why undefined reference to `SDL_main’ ? Although I specified -lSDL2main ?

What did I do wrong? 🙁

Advertisement

Answer

Okay, it was because of the main functions signature, that has to be declared as:

JavaScript

according to the official SDL FAQ:

Make sure that you are declaring main() as:

JavaScript

You should be using main() instead of WinMain() even though you are creating a Windows application, because SDL provides a version of WinMain() which performs some SDL initialization before calling your main code. If for some reason you need to use WinMain(), take a look at the SDL source code in src/main/win32/SDL_main.c to see what kind of initialization you need to do in your WinMain() function so that SDL works properly.

Advertisement