title: Compiling SDL2 windows EXE from Linux with mingw 'The application was unable to start correctly'
body: <p>So I'm trying to build this example SDL 2 program on VSCode on Ubuntu 21.10:</p>
  <pre><code>#include &lt;SDL2/SDL.h&gt;
  #include &lt;SDL2/SDL_timer.h&gt;
  #include &lt;stdio.h&gt;
   
  int main(int argc, char *argv[])
  {
   
      // retutns zero on success else non-zero
      if (SDL_Init(SDL_INIT_EVERYTHING) != 0) {
          printf(&quot;error initializing SDL: %s\n&quot;, SDL_GetError());
      }
      SDL_Window* win = SDL_CreateWindow(&quot;GAME&quot;, // creates a window
                                         SDL_WINDOWPOS_CENTERED,
                                         SDL_WINDOWPOS_CENTERED,
                                         1000, 1000, 0);
   
      // triggers the program that controls
      // your graphics hardware and sets flags
      Uint32 render_flags = SDL_RENDERER_ACCELERATED;
   
      // creates a renderer to render our images
      SDL_Renderer* rend = SDL_CreateRenderer(win, -1, render_flags);
   
      // creates a surface to load an image into the main memory
      SDL_Surface* surface;
   
      // loads image to our graphics hardware memory.
      SDL_Texture* tex = SDL_CreateTextureFromSurface(rend, surface);
   
      // clears main-memory
      SDL_FreeSurface(surface);
   
      // let us control our image position
      // so that we can move it with our keyboard.
      SDL_Rect dest;
   
      // connects our texture with dest to control position
      SDL_QueryTexture(tex, NULL, NULL, &amp;dest.w, &amp;dest.h);
   
      // adjust height and width of our image box.
      dest.w /= 6;
      dest.h /= 6;
   
      // sets initial x-position of object
      dest.x = (1000 - dest.w) / 2;
   
      // sets initial y-position of object
      dest.y = (1000 - dest.h) / 2;
   
      // controls annimation loop
      int close = 0;
   
      // speed of box
      int speed = 300;
   
      // annimation loop
      while (!close) {
          SDL_Event event;
   
          // Events management
          while (SDL_PollEvent(&amp;event)) {
              switch (event.type) {
   
              case SDL_QUIT:
                  // handling of close button
                  close = 1;
                  break;
   
              case SDL_KEYDOWN:
                  // keyboard API for key pressed
                  switch (event.key.keysym.scancode) {
                  case SDL_SCANCODE_W:
                  case SDL_SCANCODE_UP:
                      dest.y -= speed / 30;
                      break;
                  case SDL_SCANCODE_A:
                  case SDL_SCANCODE_LEFT:
                      dest.x -= speed / 30;
                      break;
                  case SDL_SCANCODE_S:
                  case SDL_SCANCODE_DOWN:
                      dest.y += speed / 30;
                      break;
                  case SDL_SCANCODE_D:
                  case SDL_SCANCODE_RIGHT:
                      dest.x += speed / 30;
                      break;
                  default:
                      break;
                  }
              }
          }
   
          // right boundary
          if (dest.x + dest.w &gt; 1000)
              dest.x = 1000 - dest.w;
   
          // left boundary
          if (dest.x &lt; 0)
              dest.x = 0;
   
          // bottom boundary
          if (dest.y + dest.h &gt; 1000)
              dest.y = 1000 - dest.h;
   
          // upper boundary
          if (dest.y &lt; 0)
              dest.y = 0;
   
          // clears the screen
          SDL_RenderClear(rend);
          SDL_RenderCopy(rend, tex, NULL, &amp;dest);
   
          // triggers the double buffers
          // for multiple rendering
          SDL_RenderPresent(rend);
   
          // calculates to 60 fps
          SDL_Delay(1000 / 60);
      }
   
      // destroy texture
      SDL_DestroyTexture(tex);
   
      // destroy renderer
      SDL_DestroyRenderer(rend);
   
      // destroy window
      SDL_DestroyWindow(win);
       
      // close SDL
      SDL_Quit();
   
      return 0;
  }
  </code></pre>
  <p>If I compile for Linux, it works just fine. It basically does nothing but creates a window on the screen named &quot;GAME&quot;.
  But I am also trying to cross-compile for Windows using minGW.
  These are the commands I am using to do that:</p>
  <pre><code>x86_64-w64-mingw32-gcc -L/home/russell/Windows_Dev/SDL2-devel-2.0.16-mingw/SDL2-2.0.16/x86_64-w64-mingw32/lib -I/home/russell/Windows_Dev/SDL2-devel-2.0.16-mingw/SDL2-2.0.16/x86_64-w64-mingw32/include -fstack-protector -std=c17 -Wall -g -o obj/main.o -c src/main.c
  </code></pre>
  <p>and</p>
  <pre><code>x86_64-w64-mingw32-gcc -L/home/russell/Windows_Dev/SDL2-devel-2.0.16-mingw/SDL2-2.0.16/x86_64-w64-mingw32/lib -I/home/russell/Windows_Dev/SDL2-devel-2.0.16-mingw/SDL2-2.0.16/x86_64-w64-mingw32/include -fstack-protector -std=c17 -Wall -g -o build/Test.exe obj/main.o -lmingw32 -lSDL2main -lSDL2 -mwindows -lm
  </code></pre>
  <p>which compiles perfectly fine. However, if I try to run the program on my Windows 10 machine, I get an error that says:</p>
  <pre><code>The application was unable to start correctly (0xc000007b).&quot;
  </code></pre>