Scratz's profileScratz 的小果园PhotosBlogListsMore Tools Help

Blog


    9/28/2008

    Using GTK+ on Win64

    If you are coding GTK+ for win32 only, stop here and go to Glade for Win32.

    GTK+ team has recently released development packages for win64, but without Glade, and there seems to be nobody working on it at this time. I spent nearly every night in this week on it and has just managed to get it work. This is my first time to build staffs from source, so I encountered and solved a lot of problems. I'm going to walk my path again and write it down, and hopefully it will help you.

    Prerequisites

    • mingw-w64
      Download the latest complete toolchain. You can choose mingw-w64-bin_i686-mingw_*.zip that is a cross compiler toolchain working on both win32 and win64. If you own a copy of 64-bit Windows, you can also use mingw-w64-bin_x86_64-mingw_*.zip that is a native compiler toolchain for win64 only, which is also my situation.Unpack it to C:\mingw-w64 or anywhere as you wish, add C:\mingw-w64\bin to your Path environment variable.
    • msys
      Download the latest version here (currently msysCORE-1.0.11-20080826.tar.gz), unpack it to C:\msys and add C:\msys\bin to your Path. Don't use the "Current Release" version 1.0.10, for it will crash on Windows Vista. You can create a desktop shortcut to msys.bat, which launches a Unix-like shell used to build our packages.
    • GTK+ Development Packages
      Downloag the all-in-one bundle from the official GTK+ web site. Unpack it to C:\GTK or anywhere as you wish, add C:\GTK\bin to your Path, and set the PKG_CONFIG_PATH environment variable to C:\GTK\lib\pkgconfig.
      You also need libjpeg and libtiff required by libglade we're going to build.
    • Test Your Settings
      Open msys shell by running msys.bat, and execute make --version, gcc --version and pkg-config --cflags gtk+-2.0. Make sure you get outputs about version or make, version of gcc and the include directories of GTK+. If not, you'd better go through the above requirements again.
    Now you're ready to compile. Glade depends on several libraries, and they seem to have no win64 binaries available too. In a nutshell, you need to build the following things one by one: libiconv, libxml2, libglade, hicolor-icon-theme and Glade3.

    libiconv

    • Download libiconv
      Though the Official GTK+ site provides a small static library called win_iconv as a replacement for the much larger GNU libiconv, libxml prefers the latter for now. You get the latest source code of libiconv from here.
    • Hack libtool
      libtool has a bug on windows. It treats all *.a files as static libraries which would cause linking fail. I don't know how to make it distinguish static and dynamic libraries, but since all we have now are dynamic ones, this hacking task becomes very simple.
      Open build-aux/ltmain.sh, navigate to function func_win32_libid(), delete the entire *ar\ archive*) case, and then change
      *ar\ archive\ import\ library*)
      to
      *ar\ archive*)
      Now libtool will treat every *.a file as an archive import library.
    • Correct windres-options
      Sed expressions in windows/windres-options are wrong. Open this file and change
      sed_extract_major='/^[0-9]/{s/^\([0-9]*\).*/\1/p;q}
      a\
      0
      q
      '
      sed_extract_minor='/^[0-9][0-9]*[.][0-9]/{s/^[0-9]*[.]\([0-9]*\).*/\1/p;q}
      a\
      0
      q
      '
      sed_extract_subminor='/^[0-9][0-9]*[.][0-9][0-9]*[.][0-9]/{s/^[0-9]*[.][0-9]*[.]\([0-9]*\).*/\1/p;q}
      a\
      0
      q
      '

      to
      sed_extract_major='
      /^[0-9]/{s/^\([0-9]*\).*/\1/p
      q
      }
      a\
      0
      '
      sed_extract_minor='
      /^[0-9][0-9]*[.][0-9]/{s/^[0-9]*[.]\([0-9]*\).*/\1/p
      q
      }
      a\
      0
      '
      sed_extract_subminor='
      /^[0-9][0-9]*[.][0-9][0-9]*[.][0-9]/{s/^[0-9]*[.][0-9]*[.]\([0-9]*\).*/\1/p
      q
      }
      a\
      0
      '
    • Build And Install
    libxml2
    • Download libxml2
      Get the latest source here.
    • Hack libtool
      Please refer to "libiconv". Notice ltmain.sh is in the root directory this time.
    • Modify Source
      Open include/wsochcompat.h and delete #include <wspiapi.h>. wspiapi.h is actually not needed but leaving it would cause some linking errors.
    • Build And Install
    libglade
    • Download libglade And Hack libtool
      Get the latest source here.
    • Build And Install
    hicolor-icon-theme

    • Download hicolor-icon-theme
      Get the latest source here.
    • Build And Install
    Glade3

    • Download Glade3 And Hack libtool
      Get the latest source here.
    • Correct The Code
      Open gladeui/glade-utils.h and delete these two functions:
      void glade_util_widget_set_tooltip(GtkWidget *widget, const gchar *str);
      gboolean glade_util_version_lesser_than(gdouble a, gdouble b);

      Open gladeui/glade-builtins.h and delete these two functions:
      guint glade_builtin_key_from_string(const gchar *string);
      const gchar *glade_builtin_string_from_key(guint key);

      These four functions have only declarations without implementations. Leaving them will cause linking errors.
    • Build And Install
      Configure with GMSGFFMT=msgfmt.
    Now you have a complete development tool set of GTK+ on win64.