Building Quantum GIS with Microsoft Visual C++ 2008 Express Edition on Windows XP Professional

This tutorial shows how to include the current Quantum GIS code as a project in Microsoft Visual C++ 2008 Express on Windows XP Professional and how to install it.
Many thanks to Tim Sutton, David Willis and Juergen Fischer whose tutorial "Compiling QGIS From Source" was the basis of this tutorial.

Step 1: Microsoft Visual C++ 2008 Express Edition and Microsoft Platform SDK for Windows Server 2003 R2

Microsoft Visual C++ 2008 Express can be found here:
http://www.microsoft.com/germany/express/download/downloaddetails.aspx?p=vcpp
The installation works by itself; MSDN and SQL Server isn't necessary.

Microsoft Platform SDK for Windows Server 2003 R2 can be found here:
http://www.microsoft.com/downloads/details.aspx?FamilyId=0BAF2B35-C656-4969-ACE8-E4C0C0716ADB&displaylang=en#filelist
Choose the relevant file out of these:
PSDK-amd64.exe
PSDK-ia64.exe
PSDK-x86.exe

During the installation please necessarily choose the standard directory and choose the following options:
Configuration Options
  + Register Environmental Variables (Yes)
Microsoft Windows Core SDK
  + Tools (Yes)
    + Tools (AMD 64 Bit) (No unless this applies)
    + Tools (Intel 64 Bit) (No unless this applies)
  + Build Environment
    + Build Environment (AMD 64 Bit) (No unless this applies)
    + Build Environment (Intel 64 Bit) (No unless this applies)
    + Build Environment (x86 32 Bit) (Yes)
  + Documentation (No)
  + Redistributable Components (Yes)
  + Sample Code (No)
  + Source Code (No)
    + AMD 64 Source (No)
    + Intel 64 Source (No)
Microsoft Web Workshop (Yes)
  + Build Environment (Yes)
  + Documentation (No)
  + Sample Code (No)
  + Tools (No)
Microsoft Internet Information Server (IIS) SDK (No)
Microsoft Data Access Services (MDAC) SDK (Yes)
  + Tools
    + Tools (AMD 64 Bit) (No)
    + Tools (AMD 64 Bit) (No)
    + Tools (x86 32 Bit) (Yes)
  + Build Environment
    + Tools (AMD 64 Bit) (No)
    + Tools (AMD 64 Bit) (No)
    + Tools (x86 32 Bit) (Yes)
  + Documentation (No)
  + Sample Code (No)
Microsodt Installer SDK (No)
Microsoft Table PC SDK (No)
Microsoft Windows Management Instrumentation (No)
Microsoft DirectShow SDK (No)
Microsoft Media Services SDK (No)
Debuggin Tools for Windows (Yes)


In Microsoft Visual C++ Express you have to set the following setting under Tools -> Options -> Projects and Solutions -> VC++ Directories :
Executable files::
C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Bin

Include files:
C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include
C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include\atl
C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include\mfc

Library files:
C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Lib


Now you can close Microsoft Visual C++ Express an change to the following directory:
C:\Program Files\Microsoft Visual Studio 9.0\Common7\Tools

Edit the file vsvars32.bar and add the following lines after the last lines who starts with "@set":
@set PATH=C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Bin;%PATH%
@set INCLUDE=C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include;%INCLUDE%
@set INCLUDE=C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include\mfc;%INCLUDE%
@set LIB=C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Lib;%LIB%
@set LIB=%LIB%;C:\OSGeo4W\lib

Step 2: Important Dependencies

Now we have to attend to the dependencies of Quantum GIS. Fortunately the OSGeo4W Package helps us with that. It can be found here:
http://download.osgeo.org/osgeo4w/osgeo4w-setup.exe
Choose "Advanced Install" and the standard directory C:\OSGeo4W too. I installed the following packages (maybe some of them could be leave out, but thats my configuration):
Commandline_Utilites
curl, gdal, gdal_dev, gdal16, libgeotiff, libpq, msys, netcdf, proj, python, shapelib
Desktop Utilities
grass, qgis, qgis-dev
Libs
curl, expat, fcgi, fftw, freetype-mingw, fribidi, gdal, gdal-dev, gdal16, gdal16-grass, geos, grass-devel, gsl-devel, gsl-libs, hdf4, hdf5, iconv, libgeotiff, libjpeg, libjpeg-devel, libjpeg12, libmysql, libpng, libpq, libtiff, libxml2, mingw-libs, msvcrt, netcdf, ogdi, openssl, pdcurses, pdflib, proj, pyopengl, pyqt4, python-numpy, python-qgis, python-win32, qgis-devel, qgis-georef-gislab, qt4-devel, qt4-doc, qt4-libs, shapelib, sip, sqlite3, tcltk, wxpython, xerces-c, zlib
Web
No packages
Web_Applications
No packages

The installation might take a while.

Additionally Flex and Bison can be found here:
Flex: http://gnuwin32.sourceforge.net/downlinks/flex.php
Bison: http://gnuwin32.sourceforge.net/downlinks/bison.php
During the installation you can choose the directory C:\OSGeo4W or the standard directory. If you choose the standard directory you have to copy the following folders after installation to C:\OSGeo4W:
bin
include
lib
share

All dependencies had to be add to the environment variables. For this you have to open the "Properties" by right-clicking "My Computer". You finde the button "Environment variables" on the "Advanced" tab. Now you have to add or edit the following System variables (if they don't exist already):
INCLUDE
C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include\.

LIB
C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Lib\.

LIB_DIR
C:\OSGeo4W

Path
C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Bin\.;C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Bin\WinNT\.; C:\Program Files\Microsoft Visual Studio 9.0\VC\bin;C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE;C:\Program Files\Microsoft Visual Studio 9.0\Common7\Tools;C:\OSGeo4W\bin

Step 3: Further settings in Microsoft Visual C++ Express

Open the already known window under Tools -> Options -> Projects and Solutions -> VC++ Directories and add the following entries:
Executable files:
C:\OSGeo4W\bin

Include files:
C:\OSGeo4W\include
C:\OSGeo4W\include\qt4\Qt
C:\OSGeo4W\include\qt4\QtCore
C:\OSGeo4W\include\qt4\QtGui
C:\OSGeo4W\include\qt4\QtNetwork
C:\OSGeo4W\include\qt4\QtSvg
C:\OSGeo4W\include\qt4\QtXml
C:\OSGeo4W\include\qt4\Qt3Support

Library files:
C:\OSGeo4W\lib

Step 4: Python

Python, SIP und PyQt4 are already contained in OSGeo4W.

Step 5: CMake & SVN

CMake 2.6.4. can be found here:
http://www.cmake.org/cmake/resources/software.html
Nothing special to say about the installation.

SVN can be found here and must be extract to C:\Program Files\svn :
http://subversion.tigris.org/downloads/1.4.5-win32/apache-2.2/svn-win32-1.4.5.zip

Now add the two directories to the environment variable PATH (see end of step 2):
C:\Program Files\CMake 2.6\bin
C:\Program Files\svn\bin

Step 6: Checkout Quantum GIS

Open a "cmd.exe", change to the directory C:\dev\cpp and check out the current QGIS code with the following command:
svn co https://svn.osgeo.org/qgis/trunk/qgis

The probably upcoming message can be confirmed with a "p".

Step 7: Building and installation

Run the following commands on the command line:
cd qgis
mkdir build
cd build
cmakesetup ..

After the click on "Configure" you have to choose Microsoft Visual Studio 9.0 and watch CMake working automatically. Individual adjustments to the settings can be made after the configuration is finished.

The created file "qgisX.X.X.sln" (X.X.X. represents the current version) can be open in MSVC under File -> Open -> Project / Solution.
Change from "Debug" to "Release" in the toolbar and start the building process by right-click -> "build" on "ALL_BUILD" on the left hand side. After this is finished without any errors you can do the same on "INSTALL", which installs Quantum GIS to the default directory C:\Program Files\qgisX.X.X.

Quantum GIS can now be used as usual.

Have fun developing!
Florian Hillen



Final hint: All projects from the left hand side can be build separately. So if you change anything on your plugin or anything else, it's enough to build the single project and then install it to QGIS using "INSTALL".