Compiling the GTK+ (and Clutter) stack using Visual C++ 2008 and later

(Yes, I will write this up in Chinese later too ;) )

This will attempt to outline the process required to build the GTK+ stack (with the dependencies) on the latest Visual C++ as far as possible, as to address:

  1. There are concerns on using different CRTs on Windows in terms of stability.
  2. To help people integrate/develop/use GTK+ easier on Windows (especially under Visual Studio).
  3. It is not possible to compile the latest stable GLib (at least) with Visual C++ 6 (or even 2003) out of the box-and it is required for the latest stable GTK+ 2.x/3.x, plus other GNOME software

Preparations

  1. Please use 7-zip if you prefer to unpack the *.tar.xz tarballs via a GUI application, as it seems that WinRAR, although it supports unpacking *.tar.xz tarballs, it can mess up file permissions, causing odd security warnings to show up when opening Project Files from Visual Studio/Visual C++.
  2. If you are building the GTK+/Clutter stack on CJK (Chinese, Japanese, Korean) versions of Windows, you will most likely see C4819 errors when attempting to build the stack, possibly accompanied by an error indicating "new line in constant". Please do not attempt to save the relevant source file(s) with UTF BOM as it likely indicates that the stack has some parts that are not correctly built-this is due to an issue of the Visual C++ compiler running on CJK locales. To ensure that the code is correctly built in Visual Studio, please switch your locale (search under Google: "change the system locale" for how to do that for your version of Windows) to English (United States), reboot and rebuild, and things should build normally. This error would at least show up during the build of GLib, Pango, GTK+ (2.x and 3.x), Cogl, Clutter and any programs that include the GTK+-3.x, Cogl and Clutter headers. This is also an issue that is faced when building some other open source projects with Visual Studio, such as OpenOffice/LibreOffice, Firefox, HarfBuzz, Qt, KDE projects, etc.

  3. Please use the latest Windows SDK (aka Platform SDK) and the latest Visual C++/Studio service pack available before you begin.
  4. Please, ensure that your IDE and Visual C++ command line environment is working correctly before you begin. This includes making sure cl.exe (32-bit/64-bit) and ml.exe(32-bit)/ml64.exe(64-bit) can be run from your Visual C++ command prompt. Please, verify that your command prompt corresponds to the Visual C++ version you intend to use to compile the GTK+ stack and its corresponding applications.
  5. Set up a working folder for this entire process, such as gtk_compilation, as follows, where Platform is Win32(32-bit) or x64(64-bit, x86-64), and $(VS_VER) is vs9 (Visual C++ 2008) or vs10 (Visual C++ 2010):

mkdir c:\gtk_compilation\$(VS_VER)\$(Platform)
mkdir c:\gtk_compilation\$(VS_VER)\$(Platform)\bin
mkdir c:\gtk_compilation\$(VS_VER)\$(Platform)\include
mkdir c:\gtk_compilation\$(VS_VER)\$(Platform)\lib

It is recommended in the Visual Studio Command prompts that you do the following, which is useful for building CMake items at least:

set PATH=c:\gtk_compilation\$(VS_VER)\$(Platform)\bin;%PATH%;<path-containing-cmake.exe>
set LIB=c:\gtk_compilation\$(VS_VER)\$(Platform)\lib;%LIB%
set INCLUDE=c:\gtk_compilation\$(VS_VER)\$(Platform)\include;%INCLUDE%

The Dependencies

ZLib

(Required directly by GIO, Cairo and GDK-Pixbuf)

Download the latest ZLib source package (1.2.5 at this time of writing) from the ZLib homepage, and unpack the zip/tarball file to some location.

Decide first whether you are compiling Release or Debug-if you are compiling as debug, find the line in win32/makefile.msc:

CFLAGS  = -nologo -MD -W3 -O2 -Oy- -Zi -Fd"zlib" $(LOC)

and change it to

CFLAGS  = -nologo -MDd -W3 -Od -Zi -Fd"zlib" $(LOC)

In the Visual C++ command prompt, run the following:

cd $(the_folder_where_zlib_was_unpacked)

nmake -f win32/makefile.msc LOC="-DASMV -DASMINF" OBJA="inffas32.obj match686.obj" /*this is for 32-bit*/

nmake -f win32/Makefile.msc AS=ml64 LOC="-I. -I.\win32 -DASMV -DASMINF" OBJA="inffasx64.obj gvmat64.obj inffas8664.obj" /*this is for x86-64, run this command as a single line*/

The compilation of ZLib should be done in a minute at this point. For convenience reasons, you should also copy the resulting zdll.lib as zlib1.lib [or zlib1d.lib if compiling as debug if building for glib-2.42.2 or earlier](but please do not copy the DLL file as such!) Copy the resulting files as follows:

  • -Copy zlib.h and zconf.h in ZLib's $(srcroot) to c:\gtk_compilation\$(VS_VER)\$(Platform)\include
    -Copy zdll.lib and zlib1.lib in ZLib's $(srcroot) to c:\gtk_compilation\$(VS_VER)\$(Platform)\lib
    -Copy zlib1.dll in ZLib's $(srcroot) to c:\gtk_compilation\$(VS_VER)\$(Platform)\bin

LibPNG

(This is required directly by Cairo and GDK-Pixbuf)

Note that we will be using version 1.6.x here, and this package depends on ZLib...

Download the latest LibPNG sources from the LibPNG homepage.

Unpack the source archive to some location, say c:\gtk_compilation\, and open a Visual Studio command prompt, with the CMake executables in its PATH. Run the following:

  • -cd c:\gtk_compilation\
    -mkdir libpng.build
    -cd libpng.build
    -cmake ..\libpng-x.y.z -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=[Release|Debug|RelWithDebugInfo] -DCMAKE_INSTALL_PREFIX=c:\gtk_compilation\$(VS_VER)\$(Platform)
    -nmake
    -nmake test
    -nmake install

Pixman Library

(This is required for all builds of Cairo)

  1. Download the latest stable sources from Cairo Homepage.

  2. Unpack the sources in c:\gtk_compilation\.
  3. Download the Project Files used to compile the Pixman library with Visual Studio pixman-vsproj.zip-unzip the .zip file in Pixman's srcroot. This project file set will build pixman-0.28.x

  4. Open pixman.sln in $(srcroot)\build\win32\vs9 (VS 2008) or $(srcroot)\build\win32\vs10 (VS 2010), and build upon selecting the appropriate configuration. The .DLL, .Lib and header files will be copied to their appropriate locations (in c:\gtk_compilation\$(VS_VER)\$(Platform)\bin, c:\gtk_compilation\$(VS_VER)\$(Platform)\lib and c:\gtk_compilation\$(VS_VER)\$(Platform)\include respectively) upon successful build.

libjpeg-turbo (Optional for GDK-Pixbuf)

(Since gdk-pixbuf-2.31.x, it is recommended that libjpeg-turbo be used instead of IJG JPEG, as it is better maintained, and building the DLLs would be much easier, via CMake)

(Only required directly by GDK-Pixbuf if not using the GDI+ image loaders)

Download the latest nasm assembler from NASM homepage, you could either download the Win32 binaries or build it from source-please refer to the instructions in that package. nasm.exe needs to be in your PATH.

Download the latest libjpeg-turbo sources from the libjpeg-turbo homepage.

Unpack the source archive to some location, say c:\gtk_compilation\, and open a Visual Studio command prompt, with the CMake executables in its PATH. Run the following:

  • -cd c:\gtk_compilation\
    -mkdir libjpegt.build
    -cd libjpegt.build
    -cmake ..\libjpeg-turbo-x.y.z -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=[Release|Debug|RelWithDebugInfo] -DCMAKE_INSTALL_PREFIX=c:\gtk_compilation\$(VS_VER)\$(Platform)
    -cmake-gui (if you need to select a IJG JPEG 7 or 8 compatibility layer, a layer for version 9 does not exist)
    -nmake
    -nmake test (if on Visual Studio 2010 or later this might fail, but don't worry about it)
    -nmake install

LibTIFF (Optional for GDK-Pixbuf)

(Only required directly by GDK-Pixbuf if not using the GDI+ image loaders; this requires ZLib and libjpeg-turbo)

Get the latest stable sources from http://remotesensing.org/libtiff/ (it is 4.0.3 at this time of writing), and unpack the sources.

1. Open nmake.opt in the root folder of the sources and change the following:

#JPEGDIR        = d:/projects/jpeg-6b                              -to-
JPEGDIR         = c:/gtk_compilation/$(VS_VER)/$(Platform)

#JPEG_INCLUDE   = -I$(JPEGDIR)                                     -to-
JPEG_INCLUDE    = -I$(JPEGDIR)/include

JPEG_LIB        = libjpeg.lib                                      -to-
JPEG_LIB        = $(JPEGDIR)/lib/jpeg.lib

#ZLIBDIR        = d:/projects/zlib-1.2.1                           -to-
ZLIBDIR         = c:/gtk_compilation/$(VS_VER)/$(Platform)

#ZLIB_INCLUDE   = -I$(ZLIBDIR)                                     -to-
ZLIB_INCLUDE    = -I$(ZLIBDIR)/include

ZLIB_LIB        = zlib1.lib                                        -to-
ZLIB_LIB        = $(ZLIBDIR)/lib/zlib1.lib

#USE_WIN_CRT_LIB = 1                                               -to-
USE_WIN_CRT_LIB = 1

(changes below are only for building debug builds)
OPTFLAGS =      /Ox /MD /EHsc /W3 /D_CRT_SECURE_NO_DEPRECATE       -to-
OPTFLAGS =      /Od /MDd /Zi /EHsc /W3 /D_CRT_SECURE_NO_DEPRECATE

2. Run nmake -f makefile.vc, and remember to embed the manifests of the DLL and the Exe files if Visual C++ 2008 is used.

3. Put the files as follows:

  • -tiff.h, tiffconf.h, tiffio.h, tiffio.hxx and tiffvers.h in c:\gtk_compilation\$(VS_VER)\$(Platform)\include
    -libtiff_i.lib in c:\gtk_compilation\$(VS_VER)\$(Platform)\lib
    -libtiff.dll in c:\gtk_compilation\$(VS_VER)\$(Platform)\bin
    -All .exe files in c:\gtk_compilation\$(VS_VER)\$(Platform)\bin

JASPER (JPEG-2000 library)

Get the latest JASPER sources from http://www.ece.uvic.ca/~mdadams/jasper/

Unpack the sources, and open the Visual C++ 6 project files in src\msvc-say yes when the system asks to confirm the project conversion. If you are using Visual C++ 2010, you will probably need to use Visual C++ 2008 (Express will do) to convert the project files to the Visual C++ 2008 format first before converting to Visual C++ 2010 format [1].

1. Prior to build, change the "Runtime Library" property (in Properties[of project]->C/C++->Code Generation) to "Multithreaded DLL (/MD)" [Release] or "Multithreaded DLL Debug(/MDd)" [Debug] for each project.

2. If building for 64-bit, please add a 64-bit configuration by using the "Configuration Manager"

3. Build the project.

4. Put the files as follows:

  • -The entire jasper folder (found in src\libjasper\include) in c:\gtk_compilation\$(VS_VER)\$(Platform)\include
    -libjasper.lib in c:\gtk_compilation\$(VS_VER)\$(Platform)\lib
    -All .exe files in c:\gtk_compilation\$(VS_VER)\$(Platform)\bin

FreeType (Optional for Cairo and Pango)

(This is required if FontConfig/Freetype support is needed in Pango and Cairo)

  1. Download the latest source release from http://sourceforge.net/projects/freetype/files/freetype2/, and open the Visual C++ 2008 or 2010 project files in $(srcroot)\builds\win32\vc2008 or $(srcroot)\builds\win32\vc2010.

  2. Add a 64-bit configuration using "Configuration Manager" if applicable. Prior to compiling, please ensure that ftbdf.c from $(FreeType_src_root)\src\base is included in the project under freetype->Source Files->FT_MODULES in the project, or at least is listed as one of the source files to compile.

  3. Select the Debug or Release configuration, and build the project.
  4. Put the files as follows:
    • -the freetype.lib static library into c:\gtk_compilation\$(VS_VER)\$(Platform)\lib
      -everything in $(srcroot)\include into c:\gtk_compilation\$(VS_VER)\$(Platform)\include

Expat (Optional for Cairo and Pango)

(This is required if FontConfig/Freetype support is needed in Pango and Cairo, required by FontConfig)

  1. Download the latest version from http://sourceforge.net/projects/expat/files/expat/.

  2. Unpack the source archive to some location, say c:\gtk_compilation\, and open a Visual Studio command prompt, with the CMake executables in its PATH. Run the following:

    -cd c:\gtk_compilation\
    -mkdir expat.build
    -cd expat.build
    -cmake ..\expat-x.y.z -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=[Release|Debug|RelWithDebugInfo] -DCMAKE_INSTALL_PREFIX=c:\gtk_compilation\$(VS_VER)\$(Platform)
    -nmake
    -nmake test
    -nmake install

FontConfig (Optional for Cairo and Pango)

(This is required if FontConfig/Freetype support is needed in Pango and Cairo; FreeType and Expat are required-the MSVC builds using FontConfig are not that well mainatined on my side, sorry)

  1. Download the latest release from http://www.freedesktop.org/software/fontconfig/release/, and unpack it in c:\gtk_compilation\.

  2. Download my set of Visual C++ 2008 support files to compile FontConfig from fontconfig_vs9.zip, and unzip that file in $(srcroot) of fontconfig. This includes a dirent implementation and a stdint.h implementation suitable for Visual C++ and a stub unistd.h required to build FontConfig. (Note: this project file set will build FontConfig 2.8.0-it is currently not recommended to build any FontConfig version later than 2.8.0 as there apparently are problems in making the things working nicely with the Visual C++ builds. If you want to give a recent version a try start from fontconfig_vs12.zip (fontconfig 2.5.3, Visual C++ 2013))

  3. If using Visual C++ 2010, you may upgrade the projects directly, but you may have to update the "Additional Include Directories" and "Additional Library Directories" to c:\gtk_compilation\$(VS_VER)\$(Platform)\include and c:\gtk_compilation\$(VS_VER)\$(Platform)\lib respectively.
  4. If building 64-bit, add a 64-bit configuration using "Configuration Manager", select your build configuration, and compile.
  5. Put the files as follows (For fonts.conf and fonts.dtd, create the destination folder if necessary):

    -The DLL and EXE files in Debug (or Release) into c:\gtk_compilation\$(VS_VER)\$(Platform)\bin
    -The fontconfig folder in $(srcroot) into into c:\gtk_compilation\$(VS_VER)\$(Platform)\include
    -The fontconfig.lib in Debug (or Release) into c:\gtk_compilation\$(VS_VER)\$(Platform)\lib
    -The fonts.conf and fonts.dtd files into c:\gtk_compilation\$(VS_VER)\$(Platform)\etc\fonts

gettext-runtime

(This is required for all components of the GTK+ stack)

This is one of the harder ones to build with Visual C++, but it is possible with a non-official package.

  1. Make sure you have CMake installed, and it is accessible from your VS2008 or VS2010 command line! If you do not have CMake installed, get the latest stable Win32 binary from here, and navigate on the page to "Resources" -> "Download". This is also needed for compiling PCRE for those who want to.

  2. Grab gettext-0.18-runtime sources for VS9 or gettext-0.18-runtime sources for VS10 from the WinKDE project. Unpack the file that you have just downloaded into some location.

  3. Replace the intl.def in $(srcroot)\gettext-runtime\intl with this, as some needed symbols are missed from the .def file.

  4. Run from your VS2008 or 2010 (or Windows SDK) command line: cmake -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX=c:\gtk_compilation\$(VS_VER)\$(Platform). This is going to take a while-after it is done, use cmake-gui to verify that the entries (the CMAKE_BUILD_TYPE, which determines a "Debug" or "Release" build, and CMAKE_INSTALL_PREFIX) are correct, and regenerate the NMake makefiles if necessary.
  5. Run "nmake", followed by "nmake install"

PCRE (Optional for GLib)

This is optional for GLib-but people may want to do this if they want to have a PCRE DLL where they can used in multiple programs. You need to have CMake to compile this (please see the gettext-runtime section on this). Note that for the GLib regex tests to pass, you need to build the PCRE that is bundled by GLib.

  1. Grab the latest stable PCRE sources from here-note that you need at least 8.32 to build the latest stable versions of GLib.

  2. Run from your Visual Studio) command line: cmake -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX=c:\gtk_compilation\$(VS_VER)\$(Platform). This is going to take a while-after it is done, use cmake-gui to verify that the entries (the CMAKE_BUILD_TYPE, which determines a "Debug" or "Release" build, and CMAKE_INSTALL_PREFIX) are correct. Also, within the CMake GUI, you need to ensure that the UNICODE and UTF-8 options are selected, and that BUILD_SHARED_LIBS is selected. If LibBZ2 and LibReadline is not available on your system, please ensure that PCRE_SUPPORT_LIBBZ2 and PCRE_SUPPORT_LIBREADLINE are unchecked (if these options are displayed)--this part is optional as this only ensures the successful builds of the PCRE command-line tools. Regenerate the NMake makefiles.

  3. Run "nmake", followed by "nmake install"

libffi

This library is needed to build GLib (specifically GObject) and gobject-introspection, for foreign function interface usage.

  1. You will need to get the mozilla-build package from here. It's a large package, but it is the Mozilla people who managed to write the assembly code that can be built with VS so that people can make use of it everyday in Firefox 4.x+. Install the package at its suggested location-most probably c:\mozilla-build.

  2. Grab the latest libffi 3.0.10 (or later) sources from here. Unpack it somewhere.

  3. Open a mozilla-build MSYS bash prompt by using one of the start-*.bat files under c:\mozilla-build (or whereever it is installed to)-pick the one that suits your environment the best. For people using the Windows SDK to compile 64-bit apps, you may need run manually from your Windows SDK command prompt:

    set MOZBUILDDIR=c:\mozilla-build\
    set MOZILLABUILD=%MOZBUILDDIR%
    set MOZ_TOOLS=%MOZBUILDDIR%moztools-x64
    start /d "%USERPROFILE%" "" "%MOZILLABUILD%"\msys\bin\bash --login -i

    Go to the $(srcroot) of libffi-3.0.10, and run one of the following: (Note: run the configure line as is, except in c:/gtk_compilation/$(VS_VER)/$(Platform), as noted earlier!)

    ./configure CC="$(pwd)/msvcc.sh -m64" LD=link CPP='cl -nologo -EP' CFLAGS='-O2' --build=x86_64-w64-mingw32 --prefix=c:/gtk_compilation/$(VS_VER)/$(Platform) [for x64]
    ./configure CC=$(pwd)/msvcc.sh LD=link CPP='cl -nologo -EP' CFLAGS='-O2' --build=i686-pc-mingw32 --prefix=c:/gtk_compilation/$(VS_VER)/$(Platform) [for Win32]
  4. Run "make";"make install". If "make install" fails for some reason, do the following:
    • copy ffi.h and ffitarget.h from $(srcroot)\i686-pc-mingw32\include (Win32) or $(srcroot)\x86_64-w64-mingw32\include to c:\gtk_compilation\$(VS_VER)\$(Platform)\include
    • copy libffi_conveneince.lib from $(srcroot)\i686-pc-mingw32\.libs (Win32) or $(srcroot)\x86_64-w64-mingw32\.libs to c:\gtk_compilation\$(VS_VER)\$(Platform)\lib\libffi.lib (yes, rename the .lib file!)

SDL-2.x (Optional for Cogl)

This is not by itself a library under the GNOME project, but it is an optional dependency for COGL (i.e. needed if you are building COGL with the SDL winsys/backend).

If your Visual C++ installation package does not provide the DirectX (DX) SDK (such as the Express Edition), you will need DX headers and libraries for DX5 or later that will work for your version of Visual C++-please check the Microsoft website for suitable releases for the DirectX SDK (the latest available DX SDK will generally work)-unfortunately this is a large download at 450MB or so due to the number of sample code and documentation-minimally you will only need the headers and libraries (x86 and x64, if applicable) for this. Check that the DX headers and libraries can be found by your Visual C++ upon successful installation of the DX SDK.

  1. Grab the latest SDL sources from http://www.libsdl.org/, and unpack the sources in c:\gtk_compilation\.

2. Unpack the source archive to some location, say c:\gtk_compilation\, and open a Visual Studio command prompt, with the CMake executables in its PATH. Run the following:

  • -cd c:\gtk_compilation\
    -mkdir sdl2.build
    -cd sdl2.build
    -cmake ..\SDL2-x.y.z -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=[Release|Debug|RelWithDebugInfo] -DCMAKE_INSTALL_PREFIX=c:\gtk_compilation\$(VS_VER)\$(Platform)
    -nmake
    -nmake test
    -nmake install

ICU (Optional for libxml2)

This is the widely-used opensource library that is used to deal with Unicode, which is an optional dependency of libxml2.

  1. Grab the latest sources for ICU4C from http://site.icu-project.org/, and unpack the sources in c:\gtk_compilation.

  2. If you are using Visual Studio 2008, you will need to follow the Cygwin build instructions for Visual Studio, please consult the ICU4C readme files for instructions on this, including the Cygwin packages that are needed. Pass in the --prefix argument to the ./runConfigureICU script to point to c:/gtk_compilation/vs9/$(Platform), run make and make install.
  3. For Visual Studio 2010 and later, open the solution file in c:\gtk_compilation\icu\source\allinone\allinone.sln. Convert the project files if prompted, and build your desired configuration.
  4. For Visual Studio 2010 and later, copy the .lib files in c:\gtk_compilation\icu\source\lib (32-bit builds) or c:\gtk_compilation\icu\source\lib64 (64-bit builds) to c:\gtk_compilation\$(VS_VER)\$(Platform)\lib\, copy the DLLs and .exe files in c:\gtk_compilation\icu\source\bin (32-bit builds) or c:\gtk_compilation\icu\source\bin64 (64-bit builds) to c:\gtk_compilation\$(VS_VER)\$(Platform)\bin, and everything in c:\gtk_compilation\icu\source\include to c:\gtk_compilation\$(VS_VER)\$(Platform)\include.

libepoxy

libepoxy is a small library that is used to acquire function pointers from the OpenGL implementation that is provided by the graphics (GPU) driver. It is needed for GTK+ 3.15.x and later, due to OpenGL support in GDK and GTK. You will need Python to build this.

  1. Since the original sources of libepoxy is only buildable with GCC, download the updated sources from libepoxy-1.2.tar.bz2 and unpack the tarball in c:\gtk_compilation. A pull request is under review for the changes needed to support building libepoxy with Visual Studio, and this part will be updated when that happens and a new official release that contains it is done.

  2. If you are not using Visual Studio 2013 or later, you will need to get a working implementation of stdint.h (this is provided with Visual Studio 2010 and 2012), inttypes.h and stdbool.h, and put them in c:\gtk_compilation\$(VS_VER)\$(Platform)\include. They can be acquired by searching for msinttypes (stdint.h, inttypes.h) and adapting gnulib's stdbool.h, for example.
  3. Check src\Makefile.vc to ensure that PYTHONDIR is pointing to your Python installation, either a 32-bit or a 64-bit (x64) installation of Python will do.
  4. Run "nmake Makefile.vc CFG=release" or "nmake Makefile.vc CFG=debug" in src\ for a release or debug build.
  5. Optionally, add src\ into your PATH and run the previous step in test\. Run the tests by running the built .exe's.
  6. Copy gl.h, gl_generated.h, wgl.h and wgl_generated.h include\epoxy to c:\gtk_compilation\$(VS_VER)\$(Platform)\include\epoxy (create the folder if needed), copy src\epoxy.lib to c:\gtk_compilation\$(VS_VER)\$(Platform)\lib and copy the built DLL in src\ to c:\gtk_compilation\$(VS_VER)\$(Platform)\bin.

Now, onto the GTK+ stack!

Whew-it's a long list of dependencies, huh? Now, we are ready to build the GTK+ stack-note that I am listing Cairo in this section because Cairo optionally depends on GObject (but this optional dependency of Cairo on GObject is a hard requirement for GTK+-3.x and Clutter 1.6+)

GLib

This set of libraries forms the basis of the GTK+ (GNOME) stack, required by all parts of the GTK+ core stack (ATK, Pango, GDK-Pixbuf, GTK+) and most GNOME components, such as COGL and Clutter.

This package requires gettext-runtime, ZLib and libFFI (libFFI is required for GLib 2.29.x or later only). PCRE is optionally required-it is included in the GLib tarball.

  1. Grab the latest stable/unstable tarball from the GNOME FTP. Unpack the tarball in c:\gtk_compilation\.
  2. Open the Visual C+ solution file in GLib's $(srcroot)\build\win32\vs9 (VS 2008) or $(srcroot)\build\win32\vs10 (VS2010). If you like to use your own copy of PCRE, use the configurations with the _ExtPCRE suffix.
  3. Select your desired configuration and build within the Visual C++ IDE. Upon successful compilation, the build results will end up in c:\gtk_compilation\$(VS_VER)\$(Platform), with the DLLs, LIBs, utilities and headers put in their appropriate places.
  4. If you plan to compile COGL (and Clutter), you will need to open $(srcroot)\gobject\glib-mkenums.in, find the line:

    print "glib-mkenums version glib-@GLIB_VERSION@\n";
    and replace @GLIB_VERSION@ to be the version of GLib that you have just compiled. Save the file as c:\gtk_compilation\$(VS_VER)\$(Platform)\bin\glib-mkenums--this is the PERL script that is used by some GNOME libraries to generate enumeration sources at compile time, if it is not already installed by the build process.

ATK

This library acts as the accessibility layer for GNOME/GTK+, and is also used by Clutter.

This package requires GLib and gettext-runtime.

  1. Grab the latest stable/unstable tarball from the GNOME FTP. Unpack the tarball in c:\gtk_compilation\.
  2. Open the Visual C+ solution file in ATK's $(srcroot)\build\win32\vs9 (VS 2008) or $(srcroot)\build\win32\vs10 (VS2010).
  3. Select your desired configuration and build within the Visual C++ IDE. Upon successful compilation, the build results will end up in c:\gtk_compilation\$(VS_VER)\$(Platform), with the DLLs, LIBs and headers put in their appropriate places.

GDK-Pixbuf

This library forms the basis of image loading and handling in GTK+ and GNOME, and is also used by COGL.

This package requires LibPNG, ZLib, gettext-runtime and GLib at the minimum. You will need to also build and install the IJG JPEG, LibTIFF and JASPER (JEPG-2000 library) beforehand if you choose not to use GDI+ (the *_NoGDIP configurations; the GDI+ headers and libraries are part of the standard Windows/Platform SDK installation).

  1. Grab the latest stable/unstable tarball from the GNOME FTP. Unpack the tarball in c:\gtk_compilation\.
  2. Open the Visual C+ solution file in GDK-Pixbuf's $(srcroot)\build\win32\vs9 (VS 2008) or $(srcroot)\build\win32\vs10 (VS2010).
  3. Select your desired configuration and build within the Visual C++ IDE. Upon successful compilation, the build results will end up in c:\gtk_compilation\$(VS_VER)\$(Platform), with the DLLs, LIBs, utilities and headers put in their appropriate places.

Cairo

[ (2014/02/10, 2014/08/06): Please note, if you are attempting to build the stack with Visual Studio 2010 and later, you will most probably need to turn off Whole Program Optimization as this likely means a bug in Cairo and/or the Visual Studio Optimization which will likely cause cairo to assert and crash in cairo-polygon.c in line 296]

This is not a GNOME component by itself, but is used and required by Pango, GTK+ and COGL/Clutter. Note that in order to build and run GTK+3.x and Clutter, GObject support is also required. Please get the latest possible version of the 1.12 release series as many Windows functionality and stability bugs were fixed in the later 1.12.x versions, and they incorporate the patches that Alexander Larsson submitted to Cairo that fix the redrawing bugs on Windows.

This package requires GLib, LibPNG, ZLib and Pixman; if building Pango with FontConfig support, FreeType and Expat are also required.

  1. Grab the latest stable 1.12.x sources from http://cairographics.org, and unpack the tarball in c:\gtk_compilation\.

  2. Get the VS project files from cairo-vsprojects.zip, and unzip the file in Cairo's $(srcroot)

  3. Decide whether FontConfig support is needed (hint: are you planning to build GIMP with this? Are you using FontConfig in any other way?). Open cairo-vs9.sln or cairo-vs10.sln (VS 2008 or VS2010 respectively without FontConfig support); or open cairo-fc-vs9.sln or cairo-fc-vs10.sln (VS2008 or VS2010 respectively with FontConfig support). Select your configuration and build Cairo. The *_GL configs do not currently build as they require GL extensions which is unable to link properly on Windows.

  4. Note that Cairo and cairo-gobject are built into 2 seperate DLLs. The build results will be copied to c:\gtk_compilation\$(VS_VER)\$(Platform), with the DLLs, LIBs and headers put in their appropriate places.

Pango

This set of libraries handles the (natural) language scripting and language handling parts of GTK+ and GNOME, including COGL and Clutter.

This package depends on Cairo and GLib at the minimum. If you want to build Pango with FontConfig support, you also need to build and install FontConfig (and its dependencies) beforehand, and your Cairo must also be built with FontConfig support.

  1. Grab the latest stable/unstable tarball from the GNOME FTP. Unpack the tarball in c:\gtk_compilation\.
  2. Open the Visual C++ solution file in Pango's $(srcroot)\build\win32\$(VS_VER).
  3. Open pango.sln (if not building with FontConfig support) or pango_fc.sln (if building with FontConfig support), and select your desired configuration and build within the Visual C++ IDE. Upon successful compilation, the build results will end up in c:\gtk_compilation\$(VS_VER)\$(Platform), with the DLLs, LIBs and headers put in their appropriate places.

GTK+

Finally, we are getting into building GTK+! It has sure been a long way to get to this point!

This package depends on GLib, ATK, Pango (note that FontConfig support is not absolutely required!), GDK-Pixbuf and Cairo and their dependencies. Again, if you are building GTK+-3.x, Cairo must be built with GObject support. If you are building GTK+-3.8.x or later, you need to have Python 2.5.x or later or 3.x installed, and check whether the PythonPath entry in gtk-version-paths.vsprops (or gtk-version-paths.props) points to the correct folder where the Python executable can be found. A standard Windows binary (x86 or amd64/x86-64) from http://www.python.org will do.

  1. Grab the latest stable/unstable 2.24.x/3.x tarball from the GNOME FTP. Unpack the tarball in c:\gtk_compilation\.
  2. Open the Visual C+ solution file in GTK+'s $(srcroot)\build\win32\$(VS_VER).
  3. Select your desired configuration and build within the Visual C++ IDE. Upon successful compilation, the build results will end up in c:\gtk_compilation\$(VS_VER)\$(Platform), with the DLLs, LIBs, demo program and headers put in their appropriate places. This will conclude building the GTK+ stack with MSVC all the way through.

Note though, there are two more steps that are needed, one is to download a custom index.theme file from index.theme into c:\gtk_compilation\$(VS_VER)\$(Platform)\share\icons\hicolor (create the folder if needed) and get the latest stable adwaita-icon-theme package from Adwaita Icon Theme and put that archive into c:\gtk_compilation. Do the following:

  1. Using a shell (such as MSYS, mozilla-build or cygwin), go to c:\gtk_compilation and run: tar -Jxvf adwaita-icon-theme-(x.y.z).tar.xz, where x.y.z stands for the release version numbers, such as 3.14.0. Copy all of the contents of in the Adwaita folder in the extracted folder to c:\gtk_compilation\$(VS_VER)\$(Platform)\share\icons\hicolor. You will need the xz utility if one is not already on your system, and it must be in your PATH if it is not bundled with your MSYS, mozilla-build or cygwin. A copy of xz-utils can be obtained from http://www.tukaani.org/xz/. Please, do not use 7-zip or WinRAR for this if you intend to use the SVG-format symbolic icons in any way, as some of the scalable SVG icons will be incorrectly extracted-this part will be updated once this problem is resolved.

  2. Get the .zip file containing the symbolic icons that have been converted to PNG format from here and unzip it into c:\gtk_compilation\$(VS_VER)\$(Platform)\share\icons\hicolor.

libxml2

This is the libxml2 library that is used in GNOME to parse XML, and is a required depedency of libcroco, librsvg and gtksourceview. This library is listed here, although it does not hard-depend on other GNOME libraries, as it is a GNOME library by itself. This library optionally depends on ZLib, iconv and ICU.

  1. Get the latest libxml2 release tarball from http://xmlsoft.org/, and unpack it in c:\gtk_compilation.

  2. Open win32\Makefile.msvc in the libxml2 sources, and add this line after CFLAGS = $(CFLAGS) /I$(XML_SRCDIR) /I$(XML_SRCDIR)\include /I$(INCPREFIX):
    CFLAGS = $(CFLAGS) /Ic:\gtk_complation\$(VS_VER)\$(Platform)\include.
    Add this line after LDFLAGS = $(LDFLAGS) /LIBPATH:$(BINDIR) /LIBPATH:$(LIBPREFIX):
    LDFLAGS = $(LDFLAGS) /LIBPATH:c:\gtk_compilation\$(VS_VER)\$(Platform)\lib.

  3. Find and change the following: (If using ZLib) zdll.lib to zlib1.lib (Release) or zlib1d.lib (debug); (If using ICU) icu.lib to icuuc.lib (Release) or icuucd.lib (debug).
  4. Using a Visual Studio (or Windows SDK) command prompt, go to the win32\ folder and run the following: cscript configure.js zlib=yes icu=yes iconv=no prefix=c:\gtk_compilation\$(VS_VER)\$(Platform). You need to explicitly specify zlib=yes and icu=yes if you want to use ZLib or ICU, and explicitly specify iconv=no if iconv support is not desired.

  5. Run nmake followed by nmake install (Release builds) or nmake DEBUG=1 followed by nmake DEBUG=1 install (Debug builds)

Going further

Note that this section may grow as time progresses, but I can't say when now.

JSON-GLib

This library is the GLib implementation of JSON scripting, and is used by the Clutter toolkit.

This library depends on GLib.

  1. Grab the latest stable/unstable tarball from the GNOME FTP. Unpack the tarball in c:\gtk_compilation\.
  2. Open the Visual C+ solution file in JSON-GLib's $(srcroot)\build\win32\vs9 (VS 2008) or $(srcroot)\build\win32\vs10 (VS2010).
  3. Select your desired configuration and build within the Visual C++ IDE. Upon successful compilation, the build results will end up in c:\gtk_compilation\$(VS_VER)\$(Platform), with the DLLs, LIBs, test programs and headers put in their appropriate places.

GObject-Introspection (g-i)

This is the package where one can create language bindings dynamically with the GTK+/Clutter stack.

This package requires the installation of the following items:

  • -GLib, as outlined above
    -LibFFI, as outlined above
    -Python 2.7 installation which matches your build config (Win32 or x64)(An official Python binary distribution will suffice. Python 3.x is unfortunately *not* supported at this time)-note that this limitation is only related to the build of the introspection files, PyGObject will work with Python-2.7.x or Python 3.1+
    -A MinGW gcc installation, this is needed as the source scanner will need a GCC preprocessor to process the headers/sources during the .gir/.typelib generation. You will need a 32-bit MinGW/GCC for 32-bit/x86 builds and a x64/x86-64 bit MinGW gcc for 64-bit builds. These can be obtained from the official MinGW site (32-bit MinGW only) and the mingw-w64 site (both 32-bit and 64-bit versions of MinGW). Work is under way to remove the GCC build-time requirement.
    -Set of pkg-config files for at least the GLib components. A sample set is available here: pkgconfig_sample_file.zip-you will need to edit those files to reflect your build/execution environment (in particular the prefix, exec_prefix, includedir and libdir). You will need to have one separate copy for each configuration (i.e. Win32/x86 vs x64, VS 2008 vs VS2010 vs VS2012 vs VS2013).

The steps to build g-i and the typelibs are outlined as follows:

  1. Grab the latest stable/unstable tarball from the GNOME FTP. Unpack the tarball in c:\gtk_compilation\
  2. Open up a Visual C++ 2008/2010 command prompt that matches your build configuration. (Visual C++/Studio Express users will need to use a Windows SDK command prompt for x64 builds)
  3. In the command prompt, go to the base directory where you extracted the GObject-Introspection sources.
    • 4.1 Check whether the definitions of PythonDir and/or PythonDirX64 matches your installation path of Python 2.6.x or 2.7.x in gi-extra-paths.vsprops or gi-extra-paths.props.

      4.2 Open the desired .sln file under build/win32/vs9 or build/win32/vs10, select your desired configuration (Win32 vs x64 and Debug vs Release), and build. The g-i headers, g-i .lib (girepository-1.0.lib, g-i DLL and tools and scripts, and the g-i scanner Python 2.x module will be installed in their appropriate places in c:\gtk_compilation\$(VS_VER)\$(Platform). Note that building the introspection files is not yet done at this point.

      4.3 Now we need to build the introspection files for g-i and GLib (and for libxml2, fontconfig, freetype and Cairo-GObject, and OpenGL and Win32. Open a Visual Studio (or Windows SDK) command prompt that matches your build config and navigate to c:\gtk_compilation\gobject-introspection-x.yy.z\build. Set these as environment variables or pass them in during the invocation of gi-introspection-msvc.mak (for example: nmake -f gi-introspection-msvc.mak CFG=release PYTHON2=c:\python27\python.exe PKG_CONFIG_PATH=c:\pkgconfig.vs9.win32 MINGWDIR=c:\mingw32).:

    • CFG: Build type of the g-i libraries and tools, either "release" or "debug"
    • MINGWDIR: Base directory where your MinGW/GCC installation resides, where your gcc executable resides in %MINGWDIR%\bin\gcc.exe. The installation must match your build configuration (i.e. Win32 or x64)
    • PYTHON2: (Optional if the python interpreter, python.exe, for Python 2.6.x/2.7.x is in your PATH) Location of your Python 2.6.x/2.7.x installation. The installation must match your build configuration (i.e. Win32 or x64).
    • PKG_CONFIG_PATH: Location of your GLib and possibly dependent .pc files, as mentioned previously

      Invoke the NMake Makefile gi-introspection-msvc.mak using nmake -f gi-introspection-msvc.mak <options, as noted above if not set as environment variables>. If you see Error 145 during the build of the introspection files, retry this command again, and it should work. Upon successful build, you will see a number of .gir/.typelib files in the current directory.

      4.4 Install the intropsection files using nmake -f gi-introspection-msvc.mak <options> install-introspection. If cleaning the output is desired, use nmake -f gi-introspection-msvc.mak clean

Building the Introspection Files for the other packages

This mainly covers how the introspection files for the various GNOME bits are built, g-i needs to be built and installed beforehand. Note that the introspection files for GLib (GIO/GObject/GModule/GThread/GLib) and g-i are already covered during the build process of g-i. This is supported for all the GNOME packages listed in this post, except for libxml2, libcroco, Cogl and Clutter.

  1. Make sure that the GNOME project in which generating the introspection files are already built in your desired configuration. Then open a Visual Studio (or Windows SDK) command prompt that matches your build configuration and with it navigate to the "build" folder (or "build/win32" folder for JSON-GLib), where there will be a <project_name_or_project_name_initials>_introspection-msvc.mak NMake Makefile. Set or pass in the following environment variables (see section 4.x from g-i) to <project_name_or_project_name_initials>_introspection-msvc.mak (which stand for the <options> part below:

    • CFG: Build type of the g-i libraries and tools, either "release" or "debug"
    • MINGWDIR: Base directory where your MinGW/GCC installation resides, where your gcc executable resides in %MINGWDIR%\bin\gcc.exe. The installation must match your build configuration (i.e. Win32 or x64)
    • PYTHON2: (Optional if the python interpreter, python.exe, for Python 2.6.x/2.7.x is in your PATH) Location of your Python 2.6.x/2.7.x installation. The installation must match your build configuration (i.e. Win32 or x64)
    • PKG_CONFIG_PATH: Location of your GLib and possibly dependent .pc files, as mentioned previously

      Run nmake -f <project_name_or_project_name_initials>_introspection-msvc.mak <options> to build the introspection files for the project, followed by nmake -f <project_name_or_project_name_initials>_introspection-msvc.mak <options> install-introspection to install the introspection files to their appropriate places under c:\gtk_compilation\$(VS_VER)\$(Platform). Use nmake -f <project_name_or_project_name_initials>_introspection-msvc.mak clean to clean up the build of introspection.

Cogl

This package forms the abstraction of OpenGL usage across various different platforms, and is currently mainly utilized by the Clutter toolkit. This will build both the Cogl main library and the Cogl-Pango library.

This package requires GDK-Pixbuf, Pango, Cairo, GLib and gettext-runtime, and it also requires the glext.h header from http://www.opengl.org/registry/api/glext.h. A working PERL interpretor is also required here, and the PERL interpretor must be in your PATH (it is done for you if you install a pre-packaged PERL interpreter using an installer, such as ActiveState PERL). If building the SDL backend (winsys) is desired, the SDL library is also required. This currently will build COGL with the Win32/WGL backend for all builds, and will also build the SDL backend if one chooses to do so.

  1. Place the glext.h header from http://www.opengl.org/registry/api/glext.h in c:\gtk_compilation\$(VS_VER)\$(Platform)\include\GL. You will also need glib-mkenums from GLib to be in c:\gtk_compilation\$(VS_VER)\$(Platform)\bin (please see step 4 of GLib). If you are intending to build and run COGL 1.14.x or later, you will need to obtain a compatible stdint.h implementation from http://code.google.com/p/msinttypes/ if you are running Visual C++ 2008, where you will need to place the stdint.h from the downloaded archive into c:\gtk_compilation\$(VS_VER)\$(Platform)\include. Visual C++ 2010 ships with stdint.h by default.

  2. Grab the latest stable/unstable tarball from the GNOME FTP. If building Cogl-1.10.0, you will also need to download the cogl.symbols from here and replace the one in $(srcroot)\cogl after you unpacked the Cogl sources. Unpack the tarball in c:\gtk_compilation\.

  3. The Visual C+ solution files can be found in Cogl's $(srcroot)\build\win32\vs9 (VS 2008) or $(srcroot)\build\win32\vs10 (VS2010). Decide whether the use of the SDL backend (the SDL backend seems experimental on Windows) is desired, and open cogl.sln (Windows/WGL backend only) or cogl_sdl.sln (both Windows/WGL and SDL backends)
  4. Select your desired configuration and build within the Visual C++ IDE. Upon successful compilation, the build results will end up in c:\gtk_compilation\$(VS_VER)\$(Platform), with the DLLs, LIBs, example programs, test programs and headers put in their appropriate places.

Clutter

This package is the Clutter toolkit (library), which is used to create fast, portable and compelling user interfaces.

This package requires COGL (with the dependent glext.h-please see item 1 from COGL), JSON-GLib, ATK, Pango, Cairo, GLib and gettext-runtime. If using the GDK backend is desired, you will also need GDK-3.x, version 3.4 or later, which is included in the GTK-3.x package. A working PERL interpretor is also required here, and the PERL interpretor must be in your PATH (it is done for you if you install a pre-packaged PERL interpreter using an installer, such as ActiveState PERL).

Please note that all configurations will include Win32/WGL backend (which is the default backend used on Windows), and the GDK backend can be built using the configurations that end with _GDK. You will need to override the backend in your code or use "set CLUTTER_BACKEND=gdk" to use the GDK backend.

  1. You will again need glib-mkenums from GLib to be in c:\gtk_compilation\$(VS_VER)\$(Platform)\bin (please see step 4 of GLib).
  2. Grab the latest stable/unstable tarball from the GNOME FTP (the stable tarballs do not yet have Visual C++ project files in them yet-this will be updated when the situation changes here). Unpack the tarball in c:\gtk_compilation\.
  3. Open the Visual C+ solution file in Clutter's $(srcroot)\build\win32\vs9 (VS 2008) or $(srcroot)\build\win32\vs10 (VS2010).
  4. Select your desired configuration and build within the Visual C++ IDE. Upon successful compilation, the build results will end up in c:\gtk_compilation\$(VS_VER)\$(Platform), with the DLLs, LIBs, example programs, test programs and headers put in their appropriate places.

[1]: It may not be possible to convert Visual C++ 6 .dsw/.dsp files to Visual C++ 2010 .sln/.vcxproj files directly. This is a known issue on Microsoft, and sorry for not posting earlier about this. Please see http://www.beta.microsoft.com/VisualStudio/feedback/details/584501/converting-vc6-dsp-files-with-vc2010-express for more details about this.

Projects/GTK+/Win32/MSVCCompilationOfGTKStack (last edited 2015-04-13 15:15:44 by Chun-wei Fan)