Friday, January 24, 2014

Using Cygwin and the MinGW Cross Compiler with SDL2

MinGW is currently the most popular way to use GCC on Windows. I recently found that there is a way of using MinGW from within Cygwin as a cross-compiler. I've recently been doing some OpenGL programming across both Linux and Windows, and using Cygwin has allowed me to keep my build system largely the same.
  1. I installed the following Cygwin 64 packages (I'm not sure if they are all necessary)
    1. mingw64-x86_64-binutils
    2. mingw64-x86_64-gcc
    3. mingw64-x86_64-gcc-core
    4. mingw64-x86_64-gcc-g++
    5. mingw64-x86_64-winpthreads
  2. Download the MinGW SDL2 development files.
  3. Extract the SDL2 development files.
  4. Copy source to dest (using SDL2-2.0.1 as the example)
    1. SDL2-2.0.1\x86_64-w64-mingw32\include\SDL2
      C:\cygwin64\usr\x86_64-w64-mingw32\sys-root\mingw\include
    2. SDL2-2.0.1\x86_64-w64-mingw32\lib\libSDL2.a
      C:\cygwin64\usr\x86_64-w64-mingw32\sys-root\mingw\lib\libSDL2.a
    3. SDL2-2.0.1\x86_64-w64-mingw32\lib\libSDL2main.a
      C:\cygwin64\usr\x86_64-w64-mingw32\sys-root\mingw\lib\libSDL2main.a
    4. SDL2-2.0.1\x86_64-w64-mingw32\bin\sdl2-config
      C:\cygwin64\bin\sdl2-config
  5. Edit C:\cygwin64\bin\sdl2-config
    1.  Change the "prefix" variable to /usr/x86_64-w64-mingw32/sys-root/mingw
    2. Remove "-XCClinker" from the linker line.
  6. Compile and link (statically)
    1.   x86_64-w64-mingw32-gcc.exe opengltest.c -o gltest.exe $(sdl2-config --cflags --static-libs) -lopengl32

No comments:

Post a Comment