Porting your Gtk+ application to windows

As you know we ported some time ago gedit to windows, so I’m writing this for saving you some time in case you wanna port your own application.

So, what should be done for porting you application to windows?

  • First, follow the great instructions armin did. As you can see, you have to make use of mingw so you can build/use the needed dependencies for your application. That instructions are done for subversion, so now that we are under git, you will have to download msysgit (this is the one I use) or any other git client.
  • Once you have mingw working, try building you application. For making this in gedit, I run: am_cv_python_pyexecutedir=/c/Python25/Lib/site-packages ac_cv_path_INTLTOOL_PERL=/c/Perl/bin/perl GMSGFMT=msgfmt ./autogen.sh –disable-spell && make && make install
  • If you didn’t get your application built, check the build errors. The main reasons for don’t having working this, is because you are using deprecated dependencies or dependencies that aren’t ported to windows, so GET RID OF THEM! In our case we had to add some ifdefing for not building bacon and for using the gio saver/loader instead of the mmap.
  • If you finally got the program working on mingw the pain is not yet ended. Questions like:
    • Why don’t we have plugins working?
        This problem is because windows needs some flags for building the dlls. What I had to add was:
        PLUGIN_LIBTOOL_FLAGS=”-module -avoid-version -no-undefined -mwindows -Wl,\$(top_builddir)/gedit/libgedit-\$(GEDIT_API_VERSION).a”
        -no-undefined (needed for dlls) -mwindows (needed for not showing a terminal when you execute the application and -Wl,\$(top_builddir)/gedit/libgedit-\$(GEDIT_API_VERSION).a because is needed to build directly with the library we use in gedit.
    • Why don’t we have an icon?
        In this case this is because the icon in windows is added on build time. So how can you fix that?
        In gedit we created the .ico file and a gedit.rc file.
        Then with this file you will have to add to your Makefile.am something like this:
        if PLATFORM_WIN32
        gedit-res.o: gedit.rc
        $(WINDRES) -i gedit.rc –input-format=rc -o gedit-res.o -O coffgedit_LDADD += gedit-res.o
        endif
  • After doing this you could start thinking about creating your installer. For doing this we’ve chosen Inno Setup, mainly because it was the one used in glom. For creating the installer we created two scripts build-installer which is the one that creates the directory with all needed files and dlls and call the compiler for building the installer, and gedit.iss.in that it is the one used by the inno setup compiler for creating the installer.
  • So great we have an installer that should work, but Hey it doesn’t!! Why?
      This is because we were using variables like DATADIR that gets the place where our pixmaps and other files should go. But hey, now we have installed our application in a different place that it was when we built it with mingw, so we need to get this place in a different way. In gedit we created several funcs for doing this. You can find them in gedit-dirs.ch. What we mainly do is getting the root directory with the func g_win32_get_package_installation_directory_of_module in case we are under windows and create the right path from it.
  • Finally, if you use GConf you are gonna have another problem. You have to setup the environment variable PATH at runtime. In gedit.c you have the func setup_path (borrowed from evolution) that makes that.

If you were able to read this, thanks! I hope this helps someone, I missed something like this when I worked on the gedit port.

This entry was posted in Uncategorized and tagged , , . Bookmark the permalink.

4 Responses to Porting your Gtk+ application to windows

  1. Artem Vakhitov says:

    As a lowly user, I would love if developers had a simple way to make GTK+ applications use native file/print/etc dialogs on Windows. As far as I understand (and I may well be mistaken), this is not done automatically.

    • nacho says:

      I think the print dialogs are ok, why do you want different ones? In any case, you could always ifdef a bit and use the win32 native ones.

  2. Artem Vakhitov says:

    In case of the print dialog, that’s more for the sake of consistency and familiarity, which are also very important to users. Anyway, the file dialog (the main reason for my reply) is considered lacking functionality by many people, including me.

    And the fact is, many devels are lazy to “ifdef a bit,” so users end up with a foreign and often inferior dialog when using the app in Windows. I think that it makes sense in most cases to default to native dialogs in Windows. That, of course, requires some changes in GTK+.

  3. Pingback: Twitter Trackbacks for Nacho’s Blog » Blog Archive » Porting your Gtk+ application to windows [gnome.org] on Topsy.com

Comments are closed.

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>