Compiling SDL_image with MSYS/MinGW

1. Introduction

SDL_image is an image loading library that is used with the SDL library, and almost as portable. It allows a programmer to use multiple image formats without having to code all the loading and conversion algorithms themselves. SDL_image supports BMP, GIF, JPG, LBM, PCX, PNG, PNM, TGA, TIFF, XCF, XPM and XV image formats.

SDL_image requires JPEG library for JPG image support, PGN libarary and zlib library for PGN image format support, and the TIFF library for TIFF image support.

Note: Current version of TIFF library has some problems compiling under Windows/MinGW, so we will disable support for tif file format in SDL_image library.

2. Compiling SDL_image

2.1. Compiling zlib library

Download the latest version of zlib library (version 1.2.3, at the time of writing), and save it in your MSYS home folder.

$ tar -xzvf zlib-1.2.3.tar.gz
$ cd zlib-1.2.3
$ configure --prefix=/mingw
$ make
$ make install

2.2. Compiling PNG library

Download latest version of libpng library (version 1.2.12, at the time of writing), and save it in you MSYS home directory.

Note: Current version of PNG library has some problems with installing shared version of library under MinGW system, so we will disable compilation of shared version, and patch the generated Makefile with a simple sed script, to make it work without problems.

$ tar -xjvf libpng-1.2.12.tar.bz2
$ cd libpng-1.2.12
$ ./configure --prefix=/mingw --disable-shared
$ mv Makefile Makefile.orig
$ sed -e 's/for ext in a la so; do/for ext in a la; do/' Makefile.orig > Makefile
$ make
$ make install

2.3. Compiling JPEG library

Download the source code for JPEG library (version 6b, at the time of writing), and save it in your MSYS home directory.

$ tar -xzvf jpegsrc.v6b.tar.gz
$ cd jpeg-6b
$ ./configure --prefix=/mingw --enable-static
$ make
$ make install-lib

2.4. Compiling SDL_image

Now that we have compiled all needed dependencies for SDL_image library, we can proceed and compile SDL_image library itself. Download the latest version of SDL_image library (version 1.2.5, at the time of writing), and save it in you MSYS home directory.

$ ./configure --prefix=/mingw --disable-tif --disable-jpg-shared --disable-png-shared
$ make
$ make install

3. Conclusion

This procedure will get you compiled SDL_image library, that you can use in your SDL projects. Do not forget to copy SDL_image.dll library from /mingw/bin to you application directory, if you application makes use of it.

One Response to “Compiling SDL_image with MSYS/MinGW”

  1. LlubNek says:

    Tiff compiles fine (use http://www.scons.org/wiki/KenBull/libtiff with scons in libtiff folder if configure is not working)…

    test programs like the following compile, link and run fine…

    #include “tiffio.h”
    int main() {
    TIFF* tif = TIFFClientOpen(“foo.tif”, “r”);
    if (tif) {
    // … do stuff …
    TIFFClose(tif);
    }
    return 0;
    }

    Yet SDL_image still complains…

    checking tiffio.h usability… yes
    checking tiffio.h presence… yes
    checking for tiffio.h… yes
    checking for TIFFClientOpen in -ltiff… no
    configure: WARNING: *** Unable to find Tiff library (http://www.remotesensing.org/libtiff/)
    configure: WARNING: TIF image loading disabled

    I think the problem lies in SDL_image, not libtiff.

Leave a Reply