4. Building on Windowsphp
4.1. Building with Microsoft Visual Studiohtml
This section describes how to build QGIS using Visual Studio on Windows. This is currently also how the binary QGIS packages are made (earlier versions used MinGW).python
This section describes the setup required to allow Visual Studio to be used to build QGIS.git
4.1.1. Visual C++ Express Editiongithub
The free (as in free beer) Express Edition installer is available under:web
Currently we use Visual C++ 2008 Express for 32bit builds:sql
http://download.microsoft.com/download/d/c/3/dc3439e7-5533-4f4c-9ba0-8577685b6e7e/vcsetup.exe
And Visual C++ 2010 Express for 64bit builds:express
http://download.microsoft.com/download/c/d/7/cd7d4dfb-5290-4cc7-9f85-ab9e3c9af796/vc_web.exe
You also need the Windows SDK for Windows 7 and .NET Framework 4:windows
http://download.microsoft.com/download/A/6/A/A6AC035D-DA3F-4F0C-ADA4-37C8E5D34E3D/winsdk_web.exe
4.1.2. Other tools and dependenciesapp
Download and install following packages:
You can also use flex, bison & git from
http://cygwin.com
OSGeo4W does not only provide ready packages for the current QGIS release and nightly builds of master, but also offers most of the dependencies needs to build it.
For the QGIS build you need to install following packages from OSGeo4W (select Advanced Installation):
This will also select packages the above packages depend on.
Earlier versions of this document also covered how to build all above dependencies. If you're interested in that, check the history of this page in the Wiki or the SVN repository.
4.1.3. Setting up the Visual Studio project with CMake
To start a command prompt with an environment that both has the VC++ and the OSGeo4W variables create the following batch file (assuming the above packages were installed in the default locations):
@echo off path %SYSTEMROOT%\system32;%SYSTEMROOT%;%SYSTEMROOT%\System32\Wbem;%PROGRAMFILES%\CMake 2.8\bin;%PROGRAMFILES%\subversion\bin;%PROGRAMFILES%\GnuWin32\bin set PYTHONPATH= set VS90COMNTOOLS=%PROGRAMFILES%\Microsoft Visual Studio 9.0\Common7\Tools\ call "%PROGRAMFILES%\Microsoft Visual Studio 9.0\VC\vcvarsall.bat" x86 set INCLUDE=%INCLUDE%;%PROGRAMFILES%\Microsoft Platform SDK for Windows Server 2003 R2\include set LIB=%LIB%;%PROGRAMFILES%\Microsoft Platform SDK for Windows Server 2003 R2\lib set OSGEO4W_ROOT=C:\OSGeo4W call "%OSGEO4W_ROOT%\bin\o4w_env.bat" @set GRASS_PREFIX=c:/OSGeo4W/apps/grass/grass-6.4.0 @set INCLUDE=%INCLUDE%;%OSGEO4W_ROOT%\include @set LIB=%LIB%;%OSGEO4W_ROOT%\lib;%OSGEO4W_ROOT%\lib @cmd
Start the batch file and on the command prompt checkout the QGIS source from git to the source directory QGIS
:
git clone git://github.com/qgis/QGIS.git
Create a 'build' directory somewhere. This will be where all the build output will be generated.
Now run cmake-gui
(still from cmd
) and in the Where is the source code: box, browse to the top level QGIS directory.
In the Where to build the binaries: box, browse to the 'build' directory you created.
If the path to bison and flex contains blanks, you need to use the short name for the directory (i.e. C:\Program Files
should be rewritten to C:\Progra~n
, where n
is the number as shown in `dir /x C:\``).
Verify that the 'BINDINGS_GLOBAL_INSTALL' option is not checked, so that python bindings are placed into the output directory when you run the INSTALL target.
Hit Configure
to start the configuration and select Visual Studio 9 2008
and keep native compilers
and click Finish
.
The configuration should complete without any further questions and allow you to click Generate
.
Now close cmake-gui
and continue on the command prompt by starting vcexpress
. Use File / Open / Project/Solutions and open the qgis-x.y.z.sln File in your project directory.
Change Solution Configuration
from Debug
to RelWithDebInfo
(Release with Debug Info) or Release
before you build QGIS using the ALL_BUILD target (otherwise you need debug libraries that are not included).
After the build completed you should install QGIS using the INSTALL target.
Install QGIS by building the INSTALL project. By default this will install to c:\Program Files\qgis<version> (this can be changed by changing the CMAKE_INSTALL_PREFIX variable in cmake-gui).
You will also either need to add all the dependency DLLs to the QGIS install directory or add their respective directories to your PATH.
4.1.4. Packaging
To create a standalone installer there is a perl script named 'creatensis.pl' in 'qgis/ms-windows/osgeo4w'. It downloads all required packages from OSGeo4W and repackages them into an installer using NSIS.
The script can be run on both Windows and Linux.
On Debian/Ubuntu you can just install the 'nsis' package.
NSIS for Windows can be downloaded at:
http://nsis.sourceforge.net
And Perl for Windows (including other requirements like 'wget', 'unzip', 'tar' and 'bzip2') is available at:
http://cygwin.com
4.1.5. Packaging your own build of QGIS
Assuming you have completed the above packaging step, if you want to include your own hand built QGIS executables, you need to copy them in from your windows installation into the ms-windows file tree created by the creatensis script.
cd ms-windows/ rm -rf osgeo4w/unpacked/apps/qgis/* cp -r /tmp/qgis1.7.0/* osgeo4w/unpacked/apps/qgis/
Now create a package.
./quickpackage.sh
After this you should now have a nsis installer containing your own build of QGIS and all dependencies needed to run it on a windows machine.
4.1.6. Osgeo4w packaging
The actual packaging process is currently not documented, for now please take a look at:
ms-windows/osgeo4w/package.cmd
4.2. Building using MinGW
Note: This section might be outdated as nowadays Visual C++ is use to build the "official" packages.
Note: For a detailed account of building all the dependencies yourself you can visit Marco Pasetti's website here:
http://www.webalice.it/marco.pasetti/qgis+grass/BuildFromSource.html
Read on to use the simplified approach with pre-built libraries...
MSYS provides a unix style build environment under windows. We have created a zip archive that contains just about all dependencies.
Get this:
http://download.osgeo.org/qgis/win32/msys.zip
and unpack to c:\msys
If you wish to prepare your msys environment yourself rather than using our pre-made one, detailed instructions are provided elsewhere in this document.
Download Qt opensource precompiled edition exe and install (including the download and install of mingw) from here:
http://qt.nokia.com/downloads/
When the installer will ask for MinGW, you don't need to download and install it, just point the installer to c:\msys\mingw
When Qt installation is complete:
Edit C:\Qt\4.7.0\bin\qtvars.bat and add the following lines:
set PATH=%PATH%;C:\msys\local\bin;c:\msys\local\lib set PATH=%PATH%;"C:\Program Files\Subversion\bin"
I suggest you also add C:\Qt\4.7.0\bin\ to your Environment Variables Path in the windows system preferences.
If you plan to do some debugging, you'll need to compile debug version of Qt: C:\Qt\4.7.0\bin\qtvars.bat compile_debug
Note: there is a problem when compiling debug version of Qt 4.7, the script ends with this message "mingw32-make: *** No rule to make target `debug'. Stop.". To compile the debug version you have to go out of src directory and execute the following command:
c:\Qt\4.7.0 make
Get Flex http://sourceforge.net/project/showfiles.php?group_id=23617&package_id=16424 (the zip bin) and extract it into c:\msys\mingw\bin
Follow this section in case you would like to use Python bindings for QGIS. To be able to compile bindings, you need to compile SIP and PyQt4 from sources as their installer doesn't include some development files which are necessary.
(It doesn't matter to what folder you'll install it)
http://www.riverbankcomputing.com/software/sip/download http://www.riverbankcomputing.com/software/pyqt/download
Extract each of the above zip files in a temporary directory. Make sure to get versions that match your current Qt installed version.
c:\Qt\4.7.0\bin\qtvars.bat python configure.py -p win32-g++ make make install
c:\Qt\4.7.0\bin\qtvars.bat python configure.py make make install
/!\ You can delete the directories with unpacked SIP and PyQt4 sources after a successfull install, they're not needed anymore.
In order to check out QGIS sources from the repository, you need a git client. This installer should work fine:
http://msysgit.googlecode.com/files/Git-1.7.4-preview20110204.exe
CMake is build system used by QGIS. Download it from here:
http://www.cmake.org/files/v2.8/cmake-2.8.2-win32-x86.exe
Start a cmd.exe window ( Start -> Run -> cmd.exe ) Create development directory and move into it
md c:\dev\cpp cd c:\dev\cpp
Check out sources from GIT:
git clone git://github.com/qgis/QGIS.git
As a background read the generic building with CMake notes at the end of this document.
Start a cmd.exe window ( Start -> Run -> cmd.exe ) if you don't have one already. Add paths to compiler and our MSYS environment:
c:\Qt\4.7.0\bin\qtvars.bat
For ease of use add c:\Qt\4.7.0\bin\ to your system path in system properties so you can just type qtvars.bat when you open the cmd console. Create build directory and set it as current directory:
cd c:\dev\cpp\qgis md build cd build
cmakesetup ..
Note: You must include the '..' above.
Click 'Configure' button. When asked, you should choose 'MinGW Makefiles' as generator.
There's a problem with MinGW Makefiles on Win2K. If you're compiling on this platform, use 'MSYS Makefiles' generator instead.
All dependencies should be picked up automatically, if you have set up the Paths correctly. The only thing you need to change is the installation destination (CMAKE_INSTALL_PREFIX) and/or set 'Debug'.
For compatibility with NSIS packaging scripts I recommend to leave the install prefix to its default c:\program files\
When configuration is done, click 'OK' to exit the setup utility.
make make install
Make sure to copy all .dll:s needed to the same directory as the qgis.exe binary is installed to, if not already done so, otherwise QGIS will complain about missing libraries when started.
A possibility is to run qgis.exe when your path contains c:\msys\local\bin and c:\msys\local\lib directories, so the DLLs will be used from that place.
Download and install NSIS from (http://nsis.sourceforge.net/Main_Page)
Now using windows explorer, enter the win_build directory in your QGIS source tree. Read the READMEfile there and follow the instructions. Next right click on qgis.nsi and choose the option 'Compile NSIS Script'.
This is the environment that supplies many utilities from UNIX world in Windows and is needed by many dependencies to be able to compile.
Download from here:
http://puzzle.dl.sourceforge.net/sourceforge/mingw/MSYS-1.0.11-2004.04.30-1.exe
Install to c:\msys
All stuff we're going to compile is going to get to this directory (resp. its subdirs).
Download from here:
http://puzzle.dl.sourceforge.net/sourceforge/mingw/MinGW-5.1.3.exe
Install to c:\msys\mingw
It suffices to download and install only g++
and mingw-make
components.
Flex and Bison are tools for generation of parsers, they're needed for GRASS and also QGIS compilation.
Download the following packages:
http://gnuwin32.sourceforge.net/downlinks/flex-bin-zip.php
http://gnuwin32.sourceforge.net/downlinks/bison-bin-zip.php
http://gnuwin32.sourceforge.net/downlinks/bison-dep-zip.php
Unpack them all to c:\msys\local
Paul Kelly did a great job and prepared a package of precompiled libraries for GRASS. The package currently includes:
It's available for download here:
http://www.stjohnspoint.co.uk/grass/wingrass-extralibs.tar.gz
Moreover he also left the notes how to compile it (for those interested):
http://www.stjohnspoint.co.uk/grass/README.extralibs
Unpack the whole package to c:\msys\local
Grab sources from CVS or use a weekly snapshot, see:
http://grass.itc.it/devel/cvs.php
In MSYS console go to the directory where you've unpacked or checked out sources (e.g. c:\msys\local\src\grass-6.3.cvs
)
Run these commands:
export PATH="/usr/local/bin:/usr/local/lib:$PATH" ./configure --prefix=/usr/local --bindir=/usr/local --with-includes=/usr/local/include --with-libs=/usr/local/lib --with-cxx --without-jpeg \ --without-tiff --with-postgres=yes --with-postgres-includes=/local/pgsql/include --with-pgsql-libs=/local/pgsql/lib --with-opengl=windows --with-fftw \ --with-freetype --with-freetype-includes=/mingw/include/freetype2 --without-x --without-tcltk --enable-x11=no --enable-shared=yes \ --with-proj-share=/usr/local/share/proj make make install
It should get installed to c:\msys\local\grass-6.3.cvs
By the way, these pages might be useful:
Download the sources:
http://geos.refractions.net/geos-2.2.3.tar.bz2
Unpack to e.g. c:\msys\local\src
To compile, I had to patch the sources: in file source/headers/timeval.h
line 13. Change it from:
#ifdef _WIN32
to:
#if defined(_WIN32) && defined(_MSC_VER)
Now, in MSYS console, go to the source directory and run:
./configure --prefix=/usr/local make make install
You can use precompiled DLL, no need to compile from source:
Download this archive:
http://www.sqlite.org/sqlitedll-3_3_17.zip
and copy sqlite3.dll from it to c:\msys\local\lib
Then download this archive:
http://www.sqlite.org/sqlite-source-3_3_17.zip
and copy sqlite3.h to c:\msys\local\include
Download sources:
ftp://ftp.gnu.org/gnu/gsl/gsl-1.9.tar.gz
Unpack to c:\msys\local\src
Run from MSYS console in the source directory:
./configure make make install
Download sources:
http://dfn.dl.sourceforge.net/sourceforge/expat/expat-2.0.0.tar.gz
Unpack to c:\msys\local\src
Run from MSYS console in the source directory:
./configure make make install
We're going to use precompiled binaries. Use the link below for download:
http://wwwmaster.postgresql.org/download/mirrors-ftp?file=%2Fbinary%2Fv8.2.4%2Fwin32%2Fpostgresql-8.2.4-1-binaries-no-installer.zip
copy contents of pgsql directory from the archive to c:\msys\local
We're done with preparation of MSYS environment. Now you can delete all stuff in c:\msys\local\src
- it takes quite a lot of space and it's not necessary at all.