Posted by & filed under QGIS.

Lately I have been delving deeper into the (aweful) world of Microsoft Windows – specifically looking to be able to better support Windows users trying to get to grips with running FOSSGIS on that platform. I have mentioned before on this blog how dependent I am on GDAL for my daily work. GDAL is also one of the pillars of any FOSSGIS stack (especially if you ‘belong to the c-tribe’), so being able to build it yourself on a given platform os always useful. In my case I wanted to include openjpeg V2.0 support in my Windows builds of QGIS (and hence in my windows build of GDAL).

There are several options for building GDAL under windwos yourself (ranked from insane to mindless):

  • Build all the dependencies yourself from scratch and then download GDAL from SVN and build against those dependencies.
  • Download and install OSGEO4W including the developer packages it provides, and then build GDAL against that.
  • Download an SDK created by a very fine fellow by the name of Tamas Szekeres (thanks to the folks on #gdal IRC channel for putting me on to this).
Tamas’ SDK is available in various forms – for different MSVC versions and different versions of GDAL. Also he provides two options:
  • GDAL and its dependencies provided as pre-built runtimes without.libs  and headers (around 20mb) – this is most useful if you want up to date versions of the GDAL command line tools and don’t need to compile and link against the GDAL library.
  • A complete build it yourself environment with GDAL and Mapserver source code and all the dependencies needed to build them (around 60mb).
The runtime packages are available as nightly builds so you can use bleeding edge versions of GDAL like that if you want to. The SDK is provided as a simple .zip file which you can unpack and then run the following command (you need to have MSVC installed) in order to build GDL:
nmake gdal

Simply wait a few minutes and you will have  a fresh build of the stable GDAL created in the directory called release-1500 (if you are using MSVC2008). If you want to build GDAL Trunk, I could’t find a download on Tamas’ site that directly supports that so I switched the gdal checkout inside his SDK to use trunk:

cd gdal
svn switch https://svn.osgeo.org/gdal/trunk/gdal

If may take a few minutes or longer to do the switch if you are on a slow connection like I have. After that step is done, go back up a level in the directory tree and rebuld GDAL:

cd ..
nmake gdal

Once again, go have a cup of fine South African Rooibos Tea while you wait because it may take a few minutes….

When it is finished compiling you will have a shiney new gdal19dev.dll binary build under release-1500-bin and a gdal_i.lib under release-1500/lib. Next you can build QGIS against this binary. To do so, simply follow the standard QGIS INSTALL  process for windows, but during the cmake-gui step substitute the following variables (I build GDAL using Tamas’ SDK in c:\dev\cpp\gdal-sdk\):

Replace:

GDAL_INCLUDE_DIR   : C:/OSGeo4W/include/
 GDAL_LIBRARY      : C:/OSGeo4W/lib/gdal_i.lib

With

GDAL_INCLUDE_DIR   :  C:/dev/cpp/gdal-sdk/release-1500/include
GDAL_LIBRARY       :  C:/dev/cpp/gdal-sdk/release-1500/lib/gdal_i.lib

Then generate and configure and build QGIS as per the documentation. One last thing you need to remember  : all the SDK binaries need to be copied into your QGIS runtime directory otherwise it will complain about missing GDAL.

Tamas’ work to create a GDAL SDK for Windows takes away a lot of the pain of developing ‘C-tribe’ applications under Microsoft Windows and is well worth using if you are stuck in MS land. Thanks Tamas for your efforts!

 

 

  • alexbruy

    Interesting and useful. But as I understand using this approach (SDK) we need to keep two copies of GDAL: one for QGIS (self-compiled 1.9) and second from OSGeo4W (for GRASS and other stuff).

    • http://linfiniti.com Tim Sutton

      Hi

      Yes indeed, if you remove the 1.8 dlls you may run into issues. I think it is only the one gdal dll that should be needed as duplicate though I havent tested to see for myself yet.

      Regards

      Tim

  • KarstenVennemann

    Hi,

    very handy indeed. I have 0 experience with MSVC (and building on windows). What i am trying to do is to get the new gdal driver for ESRI file GDB compiled into gdal in order to use file GDB in QGIS. Thus I downloaded MSVC 2010 Express and one of Tamas’ packages http://www.gisinternals.com/sdk/PackageList.aspx?file=release-1600-dev.zip in order to compile gdal. However runni gnmake gdal gives me :
    C:\tmp\release-1600-dev\gdal>nmake gdal
    Microsoft (R) Program Maintenance Utility Version 10.00.30319.01
    Copyright (C) Microsoft Corporation. All rights reserved.
    NMAKE : fatal error U1073: don’t know how to make ‘gdal’
    Stop.
    I have no idea what could be wrong. My question is now will the express version of MS Visual Studio 2010 will work to get gdal to compile on win ? And any idea what could be wrong ( aim on win 7 64 bit, but using the 32 bit versions of all of the above)
    Cheers
    Karsten

  • Pingback: Can I change the GDAL/OGR library that QGIS uses? | Q&A System