Note: This page is deprecated now! Please visit BuildingFromSource for the canonical resource on building QGIS from source.
Contents
Prerequisites
- Before you can start compiling QGIS, you have to build QT4 binaries.
So, please fill requirements and follow instructions from the article Building QT 4 with Visual C++ 2005 first. After you have QT4 binaries compiled, come back here.
Remember to set QTDIR environment variable as well as configure Visual C++ 2005 settings as explained there. Install Bison and Flex packages from GnuWin32 tools. Bison and Flex are required to parse qgssearchstringlexer.ll and qgssearchstringparser.yy files. The qgis_core project is configured to use those tools and expect to find them in your path.
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:
- GEOS
- GDAL/OGR
- PROJ4
- SQLite 3
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:
- Download latest GEOS version
Open Command Line window
Run C:\Program Files\Microsoft Visual Studio 8\VC\bin\vcvars32.bat script
Go to <YOUR GEOS DIR>\source
- Run nmake:
nmake -f makefile.vc
After a few minutes you should have geos.lib ready to use
Copy content of <YOUR GEOS DIR>\source\headers directory to the one pointed by $(GEOSDIR)\include macro from QGIS project settings for VC++ 2005.
Copy geos.lib to $(GEOSDIR)\lib
- 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:
- DLL files that are not produced during QGIS compilation e.g. GDAL dll, etc.
- images and icons
- resources
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:
- my own binaries of GEOS (look at directories structure above to see where I put my GEOS)
- FWTools for rest of dependencies. I used FWTools 1.0.0a7 installed in:
C:\Program Files\FWTools1.0.0a7
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
- Unzip qgis-msvc80-projects.zip archive to some temporary location
qgis-msvc80-projects directory will be created
Go into this directory and there you'll find another one called msvc80
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:
qgis.sln - Visual C++ solution file for QGIS project
qgis.suo - Visual C++ solution settings
qgis.vsprops - this is a file with global settings for all QGIS projects. Those settings are inherited by subprojects. Here I put paths to common dependencies like FWTools, GEOS, sqlite and other. You can view and edit those settings from Visual C++ IDE and View -> Property Manager dialog box.
qgis_* - directories with Visual C++ projects for QGIS modules
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:
Visual C++ 2005 project files refer to QGIS sources in the \qgis directory that's on the same level as the msvc80 directory. So, paths used by project files are relative e.g. ..\..\qgis\src\gui\main.cpp
msvc80 directory contains VC++ 2005 solution file and projects files
Building QGIS
- Open Visual C++ 2005 IDE
Open D:\myqgis\msvc80\qqis.sln file in IDE
Run Build -> Build Solution
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.
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!