/!\ Note: This page is deprecated now! Please visit BuildingFromSource for the canonical resource on building QGIS from source.

Prerequisites

Environment Configuration

Here, I'd like to give some overview of my environment I set up to build QGIS using Visual C++ 2005. QGIS has quite many dependencies so you may need to customize those settigs according to your needs.

Base Structure

Main sandbox directory:

 D:\myqgis 

Sandbox subdirs tree:

-- D:\myqgis
   |
   |-- \qgis                  - sources downloaded from SVN repository (see notes in "Get QGIS sources" section below)
   |-- \msvc80                - Visual C++ 2005 solution and project files
   |-- \geos                  - other dependencies of QGIS that I built myself e.g. geos
       |-- \include           - GEOS headers
       |-- \lib               - GEOS library (geos.lib) 

Other Dependencies

As you know, QGIS has many dependencies. At least, you will need to have following libraries with headers:

together with their dependencies like libtiff, libjpeg, etc.

You are free to build them all yourself, but you can also take ready to use binaries from FWTools package. FWTools is a set of Open Source GIS binaries for Windows (win32) and Linux (x86) systems produced by me, Frank Warmerdam (ie. FW).

/!\ Important note about GEOS

I use my own version of GEOS because that from FWTools seems to be based on C API but QGIS uses C++ API. So, you may also need to build it yourself. This is quite simple:

  1. Download latest GEOS version
  2. Open Command Line window

  3. Run C:\Program Files\Microsoft Visual Studio 8\VC\bin\vcvars32.bat script

  4. Go to <YOUR GEOS DIR>\source

  5. Run nmake:
    nmake -f makefile.vc 
  6. After a few minutes you should have geos.lib ready to use

  7. Copy content of <YOUR GEOS DIR>\source\headers directory to the one pointed by $(GEOSDIR)\include macro from QGIS project settings for VC++ 2005.

  8. Copy geos.lib to $(GEOSDIR)\lib

  9. Check Visual C++ projects settings to see if geos headers and library can be located by compiler.

Target

I configured Visual C++ solution to copy output binaries to the following directory:

C:\Program Files\Quantum GIS Dev 

You will need to copy there all runtime dependencies like:

Here you can see how does this structure looks like:

Here is a list of DLL files - QGIS dependencies:

expat_ogdi_fw.dll
gdal_fw.dll
geos_fw.dll
geotiff_fw.dll
hdf_fw.dll
hdf5dll.dll
jpeg_fw.dll
libpq.dll
libtiff_fw.dll
mfhdf_fw.dll
NCScnet_fw.dll
NCSEcw_fw.dll
NCSUtil_fw.dll
netcdf.dll
ogdi_fw.dll
proj_fw.dll
sqlite3.dll
sqlite3d.dll
xerces-c_2_6.dll
zlib_fw.dll 

As you may see, most of those files are taken from FWTools. The sqlite3d.dll file is my own version of sqlite I built myself using Visual C++ 2005 and I use for building QGIS. There is also sqlite3.dll which is used by OGR driver from FWTools. All those settings may seem quite confusing but please remember that's this is my first attempt to build QGIS using VC++ so the environment configuration can be improved, definitely. So, you may also need to check & hack after you will get it working :-)

Summary

For building QGIS with VC++ 2005 I used:

Visual C++ 2005 solution and project files are configured according to the structure explained above. So, you may need to customize project settings to your needs and configuration.

Get QGIS sources

So, let's checkout clean copy of QGIS sources:

D:\myqgis>svn co https://svn.qgis.org/repos/qgis/trunk/qgis qgis
...
A    qgis.man
A    install-sh
 U   .
Checked out revision 5059.

D:\myqgis>

After svn finish its job, you will find qgis directory in your sandbox.

/!\ It's very important to checkout QGIS sources into directory named as qgis because VC++ projects expect such structure.

qgsconfig.h

First, download this file: qgsconfig.zip

Next, copy it to this directory:

D:\myqgis\qgis 

Visual C++ project files

Now, you have to download and install project files for Visual C++ 2005.

These project files are pre-configured and provided as a foundation for your own customizations. If you have environment configured exactly as explained above you won't likely need to change project settings at all.

Download

Visual C++ solution: qgis-msvc80-projects.zip

Last update of VC++ solution: 2005-03-19

Installation

  1. Unzip qgis-msvc80-projects.zip archive to some temporary location
  2. qgis-msvc80-projects directory will be created

  3. Go into this directory and there you'll find another one called msvc80

  4. Copy msvc80 directory to your sandbox as explained above in the Base Structure section above. After this operation you should have following directory:

    D:\myqgis\msvc80 
    Inside this folder you can find solition file and subdirectories with VC++ project files:
    qqis.sln
    qqis.suo
    qgis.vsprops
    qgis
    qgis_composer
    qgis_core
    qgis_gui
    qgis_legend
    qgis_provider_delimitedtext_dll
    qgis_provider_ogr_dll
    qgis_widgets 

Visual C++ 2005 solution content:

As you can see, there are defined a few macros. Those macros are used in projects settings, e.g. $(GDALDIR)\include. So, if youre environment configuration is different, you may want to edit paths in those macros first.

/!\ Remember that:

Building QGIS

  1. Open Visual C++ 2005 IDE
  2. Open D:\myqgis\msvc80\qqis.sln file in IDE

  3. Run Build -> Build Solution

  4. After compilation is finished without any errors, you should have qgis.exe copied to C:\Program Files\Quantum GIS Dev and two providers DLLs in C:\Program Files\Quantum GIS Dev\lib\qgis.

  5. Try to lanuch qgis.exe :-)

The End

Please, remember this is my first try of building QGIS with Visual C++ 2005, so I'm still looking for some best practice. This HOWTO is more a crash course than manual solving all possible problems. So, please don't be surprised if someone will not work at first attempt.

If you have any comments, suggestions or problems, don't hesitate to contact me. I'd suggest to discuss possible issues on the list qgis-developer@lists.qgis.org.

Good Luck!

Building Quantum GIS with Visual C++ 2005 (last edited 2008-07-11 20:11:23 by MateuszLoskot)