title: How to cross-compile with SDL 2 from Linux for Windows
body: <p>I tried to compile a simple C++ program that uses SDL 2 with the mingw-w64-g++ compiler on my Arch Linux (64bits).</p>
  
  <p>For this I downloaded SDL2-devel-2.0.4-mingw.tar.gz from <a href="https://www.libsdl.org/download-2.0.php" rel="nofollow">here</a></p>
  
  <p>prog.cpp:</p>
  
  <pre><code>#include &lt;SDL.h&gt;
  
  int main ()
  {
      SDL_Init (SDL_INIT_VIDEO);
  
      SDL_Window *sdlWnd = SDL_CreateWindow ("Test", SDL_WINDOWPOS_UNDEFINED,
          SDL_WINDOWPOS_UNDEFINED, 800, 600, 0);
  
      SDL_Event event;
      bool running = true;
  
      while (running) {
          while (SDL_PollEvent (&amp;event)) {
              if (event.type == SDL_QUIT) {
                  running = false;
                  break;
              }
          }
      }
  
      return 0;
  }
  </code></pre>
  
  <p>Makefile:</p>
  
  <pre><code>GPP = x86_64-w64-mingw32-g++
  prog.exe: prog.o
      $(GPP) -o prog.exe prog.o -LSDL2-2.0.4/lib/x64 -lSDL2main -lSDL2
  prog.o: prog.cpp
      $(GPP) -o prog.o -c -ISDL2-2.0.4/include prog.cpp
  </code></pre>
  
  <p>Now making gives the error:</p>
  
  <pre><code>x86_64-w64-mingw32-g++ -o prog.exe prog.o -LSDL2-2.0.4/lib/x64 -lSDL2main -lSDL2
  Warning: corrupt .drectve at end of def file
  SDL2-2.0.4/lib/x64/SDL2main.lib(./x64/Release/SDL_windows_main.obj):(.text[main]+0x1c): undefined reference to `SDL_main'
  </code></pre>
  
  <p>Why undefined reference to `SDL_main' ? Although I specified -lSDL2main ?</p>
  
  <p>What did I do wrong? :(</p>