Sunday, January 27, 2013

Building GTK+ for x64 Windows platform

As 64-bit processors are going mainstream, software development is also going 64-bit. I am running 64-bit Windows 8, so I'd like to use 64-bit applications rather than 32-bit applications on my computer. I'm building a 64-bit GTK+ library and writing the process. This post is based on my previous post on compiling a 32-bit GTK+ library.

  1. Set up MinGW-w64 as shown in this post. I actually used my own MinGW-w64 build. Basically, this step takes the following procedure.

    • Unpack a 64-bit MinGW-w64 package into a folder, preferably C:\mingw.
    • Install Cygwin or MSYS.
    • Edit /etc/fstab to mount the MinGW-w64 folder on /mingw.
    • Run CYGWIN.BAT or MSYS.BAT to start the console.
    • Set up some environment variables, such as CC, CPP, CFLAGS, LDFLAGS, PATH, etc.
      export CC='/mingw/bin/x86_64-w64-mingw32-gcc.exe -I/mingw/include -I/mingw/x86_64-w64-mingw32/include'
      export CPP='/mingw/bin/x86_64-w64-mingw32-cpp.exe -I/mingw/include -I/mingw/x86_64-w64-mingw32/include'
      export CXX='/mingw/bin/x86_64-w64-mingw32-g++.exe -I/mingw/x86_64-w64-mingw32/include/c++/4.7.2 -I/mingw/x86_64-w64-mingw32/include/c++/4.7.2/x86_64-w64-mingw32'
      export CXXCPP='/mingw/bin/x86_64-w64-mingw32-g++.exe -E'
      export CFLAGS='-mtune=core2 -mthreads -mms-bitfields -O2 -static-libgcc'
      export CXXFLAGS='-mtune=core2 -mthreads -mms-bitfields -O2 -static-libstdc++'
      export LDFLAGS='-L/mingw/lib -L/mingw/x86_64-w64-mingw32/lib -L/mingw/lib/gcc/x86_64-w64-mingw32/4.7.2'
      export PATH=/mingw/bin:/mingw/x86_64-w64-mingw32/bin:/mingw/libexec/gcc/x86_64-w64-mingw32/4.7.2:/usr/bin
      export PKG_CONFIG_PATH=/mingw/lib/pkgconfig
  2. Build zlib. It's a compression library needed for libpng and cairo.

    tar xzvf zlib-1.2.7.tar.gz 
    cd zlib-1.2.7
    make -f win32/Makefile.gcc
    cp zlib1.dll /mingw/bin
    cp zconf.h zlib.h /mingw/include
    cp libz.a libz.dll.a /mingw/lib
  3. Compile libintl from GNU gettext. It is a library for localizing and translating programs.

    tar xzvf gettext-0.18.2.tar.gz
    cd gettext-0.18.2
    ./configure --build=x86_64-w64-mingw32 --prefix=/mingw --enable-threads=win32 --enable-relocatable
    cd gettext-runtime
    make install
  4. Get my static pkg-config and put it in /mingw/bin. Then, compile libffi. It is only needed for glib 2.30 and later.

    tar xzvf libffi-3.0.11.tar.gz 
    cd libffi-3.0.11
    ./configure --build=x86_64-w64-mingw32 --prefix=/mingw
    make install
  5. Build glib. Python should be installed using Cygwin setup beforehand.

    tar xJvf glib-2.34.3.tar.xz
    cd glib-2.34.3
    ./configure --build=x86_64-w64-mingw32 --prefix=/mingw --with-threads=win32 --with-pcre=internal --disable-debug
    make install
  6. Compile ATK.

    tar xJvf atk-2.6.0.tar.xz
    cd atk-2.6.0
    ./configure --build=x86_64-w64-mingw32 --prefix=/mingw
    make install

    For some reason, the shared library file libatk-1.0-0.dll failed to be created. I created it manually with the following command.

    cd /mingw/lib
    /mingw/bin/x86_64-w64-mingw32-gcc.exe -shared -o libatk-1.0-0.dll -Wl,--out-implib,libatk-1.0.dll.a -Wl,--whole-archive libatk-1.0.a -Wl,--no-whole-archive -L/mingw/lib -lgobject-2.0 -lglib-2.0 -lintl -L/mingw/x86_64-w64-mingw32/lib -lws2_32 -lole32 -lwinmm -lshlwapi atk-1.0.def
  7. Compile libpng.

    tar xJvf libpng-1.5.14.tar.xz
    cd libpng-1.5.14
    ./configure --build=x86_64-w64-mingw32 --prefix=/mingw
    make install
  8. Download pixman and cairo source from First, compile pixman.

    tar xzvf pixman-0.28.2.tar.gz
    cd pixman-0.28.2
    ./configure --build=x86_64-w64-mingw32 --prefix=/mingw
    make install

    Then, compile cairo.

    tar xJvf cairo-1.12.10.tar.xz
    cd cairo-1.12.10
    ./configure --build=x86_64-w64-mingw32 --prefix=/mingw
    make install
  9. Build pango.

    tar xJvf pango-1.32.6.tar.xz
    cd pango-1.32.6
    ./configure --build=x86_64-w64-mingw32 --prefix=/mingw --with-included-modules=yes
    make install
  10. Compile gdk-pixbuf. It is needed for recent versions of GTK+.

    tar xJvf gdk-pixbuf-2.26.5.tar.xz
    cd gdk-pixbuf-2.26.5
    ./configure --build=x86_64-w64-mingw32 --prefix=/mingw --without-libjasper --with-included-loaders=yes --disable-modules --disable-debug
    make install
  11. Let's build gtk+ 2.24.14 and gtk+ 3.6.4 together. Download the gtk+ source from here. First, build gtk+ 2.24.14.

    tar xJvf gtk+-2.24.14.tar.xz
    cd gtk+-2.24.14
    ./configure --build=x86_64-w64-mingw32 --prefix=/mingw --with-included-immodules=ime --disable-modules --disable-debug
    make install

    I got errors during make: cannot export gtk_accel_map_load symbol not defined, etc. These functions are indeed not defined, but they have utf8 alternatives so we can set up aliases for them. Open gtk/gtk.def and find lines ending in PRIVATE. Make the following changes. However, I am not sure if this fix makes sense.

     gtk_accel_map_load = gtk_accel_map_load_utf8 PRIVATE
     gtk_accel_map_save = gtk_accel_map_save_utf8 PRIVATE
     gtk_file_chooser_add_shortcut_folder = gtk_file_chooser_add_shortcut_folder_utf8 PRIVATE
     gtk_file_chooser_get_current_folder = gtk_file_chooser_get_current_folder_utf8 PRIVATE
     gtk_file_chooser_get_filename = gtk_file_chooser_get_filename_utf8 PRIVATE
     gtk_file_chooser_get_filenames = gtk_file_chooser_get_filenames_utf8 PRIVATE
     gtk_file_chooser_get_preview_filename = gtk_file_chooser_get_preview_filename_utf8 PRIVATE
     gtk_file_chooser_list_shortcut_folders = gtk_file_chooser_list_shortcut_folders_utf8 PRIVATE
     gtk_file_chooser_remove_shortcut_folder = gtk_file_chooser_remove_shortcut_folder_utf8 PRIVATE
     gtk_file_chooser_select_filename = gtk_file_chooser_select_filename_utf8 PRIVATE
     gtk_file_chooser_set_current_folder = gtk_file_chooser_set_current_folder_utf8 PRIVATE
     gtk_file_chooser_set_filename = gtk_file_chooser_set_filename_utf8 PRIVATE
     gtk_file_chooser_unselect_filename = gtk_file_chooser_unselect_filename_utf8 PRIVATE
     gtk_file_selection_get_filename = gtk_file_selection_get_filename_utf8 PRIVATE
     gtk_file_selection_get_selections = gtk_file_selection_get_selections_utf8 PRIVATE
     gtk_file_selection_set_filename = gtk_file_selection_set_filename_utf8 PRIVATE
     gtk_icon_source_get_filename = gtk_icon_source_get_filename_utf8 PRIVATE
     gtk_icon_source_set_filename = gtk_icon_source_set_filename_utf8 PRIVATE
     gtk_icon_info_get_filename = gtk_icon_info_get_filename_utf8 PRIVATE
     gtk_icon_theme_append_search_path = gtk_icon_theme_append_search_path_utf8 PRIVATE
     gtk_icon_theme_get_search_path = gtk_icon_theme_get_search_path_utf8 PRIVATE
     gtk_icon_theme_prepend_search_path = gtk_icon_theme_prepend_search_path_utf8 PRIVATE
     gtk_icon_theme_set_search_path = gtk_icon_theme_set_search_path_utf8 PRIVATE
     gtk_image_new_from_file = gtk_image_new_from_file_utf8 PRIVATE
     gtk_image_set_from_file = gtk_image_set_from_file_utf8 PRIVATE
     gtk_rc_add_default_file = gtk_rc_add_default_file_utf8 PRIVATE
     gtk_rc_parse = gtk_rc_parse_utf8 PRIVATE
     gtk_rc_set_default_files = gtk_rc_set_default_files_utf8 PRIVATE
     gtk_ui_manager_add_ui_from_file = gtk_ui_manager_add_ui_from_file_utf8 PRIVATE
     gtk_window_set_default_icon_from_file = gtk_window_set_default_icon_from_file_utf8 PRIVATE
     gtk_window_set_icon_from_file = gtk_window_set_icon_from_file_utf8 PRIVATE
  12. Also build the lastest version of GTK+ which is currently 3.6.4. As of this writing, many GTK+ applications still didn't upgrade to GTK+ 3.x.

    tar xJvf gtk+-3.6.4.tar.xz
    cd gtk+-3.6.4
    ./configure --build=x86_64-w64-mingw32 --prefix=/mingw --with-included-immodules=ime --disable-modules --disable-debug
    make install

    I got errors during make. Gtk-launch failed to be compiled because gdesktopappinfo.h was not found. I couldn't find an elegant solution so I did the following dirty trick.

    touch gtk/gtk-launch.o
    touch gtk/gtk-launch.exe

    I believe gtk-launch.exe is not needed on Windows so this trick is safe. I continued with "make" and "make install". Remember to remove the empty gtk-launch.exe after make install.

    rm /mingw/bin/gtk-launch.exe

Testing GTK+ 2 and GTK+ 3 Build by Running Demo

Let's quickly test the build. I found the following demo programs in /mingw/bin. Try running them.

  • gtk-demo.exe
  • gtk3-demo.exe
  • gtk3-demo-application.exe

Forsaken Libraries

The following libraries were skipped. I think it's safe to skip these libraries because Windows provide most of the needed functions. For instance, JPEG and TIFF functions are provided by Microsoft GDI+. Windows already has font facility provided by Freetype and fontconfig.

  • libiconv
  • libjpeg
  • libjasper
  • libtiff
  • freetype
  • expat or libxml2
  • fontconfig

You may have to build freetype, expat/libxml2 and fontconfig if you intend to build GIMP.

Also Read

About This Blog

KBlog logo This blog seeks to provide useful information to people, based on the author's knowledge and experience. Thanks for visiting the blog and posting your comments.

© Contents by KBlog

© Blogger template by Emporium Digital 2008

Follow by Email

Total Pageviews