Tuesday, December 25, 2007

Building GDAL Source using Visual Studio


Here is a quick post on how to build the GDAL source.

  1. Download the latest source code.
  2. Unzip the contents of the folder onto your hard drive.
  3. If you are going to use the GDAL bindings (such as the bindings for C#) then download SWIG.
    Build the swig binaries if required and copy the swig executable (SWIG.exe) to the GDAL source root folder.
  4. In the root directory of the GDAL source that you just unzipped find the file nmake.opt and open it in a text editor and perform the following edits:
    1. Set the version of VISUAL STUDIO that you are going to use to build the GDAL binaries.
      For Visual Studio 2008 - set MSVC_VER = 1500
    2. Set the GDAL_HOME variable to the GDAL source root folder. This is where all the binaries, includes, library files and html files will be copied upon successful build of GDAL.
      I prefer adding Build to the source path - as all the built files will reside under one single folder.
      eg: GDAL_HOME = "C:\Development\GDAL\gdal-1.5.0\Build"
    3. In case you are going to be building the bindings then set the location for SWIG (also see step 3).
      eg: SWIG = C:\Development\GDAL\gdal-1.5.0\swig.exe
  5. To begin building
    1. Open a Visual Studio command prompt and navigate to the folder containing the GDAL source.
    2. Run each of the following commands
      nmake /f makefile.vc
      nmake /f makefile.vc install
      nmake /f makefile.vc devinstall

      At the end of running all 3 of the above commands you will find that the GDAL dlls will reside in the GDAL source root folder. Under the Build folder you will find additional folders containing the include files, library files, html files as well as GDAL utility executables.
  6. To build the SWIG bindings for GDAL
    1. Navigate to the folder containing the bindings for the language that you need it for.
      For example for C# navigate to the following folder:
    2. Run the following commands
      nmake /f makefile.vc interface
      nmake /f makefile.vc
    3. Once the bindings have been successfully built - the dlls and executables will be found in the root folder of the language. In this case the folder will be:

For the official guide to building the GDAL sources see:
The page also lists all the different options available in the nmake.opt file.

1 comment:

BobM said...

I have ms Visual C++ 2008 Express Edition running under windows XP.
5.2 nmake /fmakefile.vc
Get the following errors:-
fatal error U1077: 'xcopy' : return code '0x1'
fatal error U1077: '"c:\Program Files\Microsoft Visual Studio 9.0\VC\BIN\nmake.EXE"' : return code '0x2'

Any suggestions ?