How to build your GTK+ application on Windows

For the last few years I have been working on getting gedit builds for Windows and it has never been as easy as now. In this post I will explain the steps you have to do to easily build your application on Windows.

  • Install the latest version of msys2. You can get it from http://msys2.github.io/. Ensure to install it on a short directory path, i.e the default c:\msys64 should be fine. Highlight that this is msys2, which compared with the previous msys system this one is fast and well maintained.
  • Open the msys2_shell.bat that you can find in c:\msys64.
  • Update it by running: pacman -Syu. This will probably update msys2 so you will have to relaunch again the shell.
  • Install the toolchain, in my case I installed the x86_64 but you can install i686 or both. To do so: pacman -S mingw-w64-x86_64-toolchain
  • Create a PKGBUILD file as you would do for Arch Linux for the package you would like to build for windows. You can find the gedit one here. Or you can find more information on how to create this file on the Arch Linux wiki.
  • Once you have the PKGBUILD file ready build it by running “makepkg-mingw -sL”. This will build your project and generate a package.
  • Install this package with pacman -U file
  • If that package your are trying to build is not already shipped by msys2 or if it is too old and you want to update it you can fork the MINGW-packages repository and add it to it and make a pull request.
  • If the package reach upstream you will not need to build it anymore in order to use it but you can simply install it by doing: pacman -S mingw-w64-x86_64-package-name
  • As an example installing gedit on Windows it is just a matter of installing msys2, update it and run “pacman -S mingw-w64-x86_64-gedit”

As you see installing and or building an application is not that difficult anymore, but as like for the case of gedit you might want to create an installer which will make easy to distribute your application. Since pacman allows you to create new roots, what I did is to create an installer based on pacman. The files can be found here. To explain a bit better how this works, here is what each file from that link mean:

  • make-gedit-installer: is a bash script which installs the base msys2 system in a specific root, in this case /tmp/gedit, and then it installs gedit and all its dependencies. Since some of them are not needed as they are optional, it also takes care of removing them.
  • make-gedit-installer.bat: it runs make-gedit-installer in 2 stages. The first one installs the basic system and the second stage installs gedit and its dependencies.
  • qt-ifw: it is used the QT sdk installer. I know it is QT but it is actually quite easy to use and anyway it is just an installer. This folder defines the packages and the installation procedure. It just a few xml files that you have to edit to set the information of your package and it also contains some Javascripts to define the installation.

I hope this helps to get your application ported to Windows and if you have any questions you can contact the msys2 team on the #msys2 channel of the OFTC IRC. Of course if you have any doubt and you prefer to contact the gedit team we are like usual in the channel on the Gimpnet IRC.

 

This entry was posted in Uncategorized. Bookmark the permalink.

9 Responses to How to build your GTK+ application on Windows

  1. willyh says:

    Nice article. Tried following the instructions but got the following:

    $ makepkg-mingw -sL
    ==> ERROR: install file (gedit-x86_64.install) does not exist.

    [WORDPRESS HASHCASH] The poster sent us ‘0 which is not a hashcash value.

  2. Alan says:

    odummaaa ????

    [WORDPRESS HASHCASH] The poster sent us ‘0 which is not a hashcash value.

  3. Eduard Gotwig says:

    Is there no alternative installer available? What about offering a MSI file instead? would be the best way.

    [WORDPRESS HASHCASH] The poster sent us ‘0 which is not a hashcash value.

  4. Pingback: tag based on what is being viewed. global $page, $paged; wp_title( '|', true, 'right' ); // Add the blog name. bloginfo( 'name' ); // Add the blog description for the home/front page. $site_description = get_bloginfo( 'description', 'display' ); if ( $sit

  5. Sam Thursfield says:

    wow, I’ve not paid attention to MSYS recently. Cool that they’ve started using Pacman !

    [WORDPRESS HASHCASH] The poster sent us ‘0 which is not a hashcash value.

  6. Ray Donnelly says:

    @Sam Thursfield

    We do not share any team members with the old MSYS project.

    MSYS2 is a MinGW-w64 creation, so MSYS haven’t started using Pacman. MSYS2 have.

    I wish we’d gone with an entirely different name sometimes!

    [WORDPRESS HASHCASH] The poster sent us ‘0 which is not a hashcash value.

  7. Michael says:

    How can I use Gtk 3.12 on Windows?

Leave a Reply

Your email address will not be published. Required fields are marked *