I'm not dead - Compiling Gtk on Windows

I've had an...interesting... week. First the kids were home the entire first week of this month (stupid winter break) which limited my computer time. Then I ended up with mastitis and spent two days in bed with a fever. Of course after the weekend when I could get to the doctor and get drugs I recovered quickly, but my house was trashed from my kids running wild. So I had to catch up on all that boring mom stuff that men seem incapable of doing (laundry, dishes, putting toys away, yeah). Now, finally, we are back to our regularly scheduled nuttiness.

There are two "compile environments" for windows. One uses Mingw (Win32 API + GCC) either with the Msys tools or Cygwin (yes you can use cygwin + msys to create native windows apps without the posix layer) for a very unixy approach to compiling on windows. These happen to be a favorite with most open source developers who aren't too big on "the Microsoft way".

The second way to compile on windows is to use Microsoft's tools - I've already done a tutorial for setting up the environment.

You can argue back and forth between the two approaches but I personally prefer to use MSVC - why? Well not because it's easier, and definitely not because other developers use it. For me it's the knowledge that Microsoft wrote the monstrosity known as windows and they probably have a better idea of how to compile things optimally for their system. Now this may be a totally inaccurate view, but somehow the idea is stuck in my brain.

In any case - I've been working on getting the entire gtk+ runtime (and all it's dependencies) compiling with MSVC so they all use the same C runtime so I don't have mysterious crashes when the runtimes disagree with each other. It has been quite an adventure. The biggest problem is that unix style build systems rely heavily on a command line environment and a configure command, while msvc leans on their visual ide. Combined with the fact that open source items that do compile on windows each use their own style of configuring it turns into a mess pretty darn fast.

Personally I've become a fan of the command line configure system set up by Wezfor PHP5. I know that Pierre has altered it slightly to build Cairo and theoretically with a little work it could be extended to cover any possible unix style build. Personally pushing for something like that would be very awesome. It's rather ingenious because it uses the windows scripting host and jscript (windows perverted javascript). However I also know PHP at least uses quite a few unix tools for windows so the dream of not needed external components to create a configure for windows is still out of reach.

Glib has an interesting configure system made of windows style makefiles, a bit of perl, and pre-created config.h files. They're all annoying called makefile.msc, which of course windows things is a management console plugin... I've found the system to be not horrible but not wonderful either.

Because of the very different methods of building with msvc on windows I've been slowly creating a monster (and I do mean monster) MSVC Solution. Because I don't have the "full version" I can't use any fancy organizing methods (sub-solutions, solution folders, whatever flavor of the week MS has concocted) which kind of stinks but I'll get by. I'm hoping to make the finished projects (along with some assorted batch files) available when it's complete. I'm structuring it so you simply download the latest source files for each project you want to compile, rename the folders to the base name of the project (gettext-0.16.2 becomes just gettext) and drop it in the source folder. Then you can build the solution and look in release or debug for neatly organized files.

However, it is taking a LONG time to complete this project. First of all, there are a LOT of packages that gtk depends on. Right now the list stands at iconv, gettext, libpng, libjpeg, pango, glib, atk, zlib, libxml2, libtiff, dirent (for making msvc cooperate), freetype, fontconfig - and I'm not even done yet.

If you're not nuts (like me) and just want the latest of all of gtk+ compiled on windows ready to go, Glade for Windows will install all the binaries, libs, headers, and everything else you need to get things compiling. I didn't have to start from scratch - other people have worked on this before but either given up or moved on. I suppose it's hard to keep something updated when new versions of code pop up all the time.

In any case, after I get gtk+ and it's myriad dependencies working, I'll be tackling php-gtk2 defs and overrides to get it working with 2.10 (yes yes, I know andrei wants to finish 2.6 first...but since my C skills are mediocre at best I'm not too good at finishing the hard stuff...we'll see)

You can take a look at the latest compiles and work I'm doing at http://callicore.net/php-gtk2



Hey,rn Gtk+ on win32 with msvc isn't easy. I spent a good year going back and forth building gtk+ on windows. In the end, I realized what I really wanted was to build software and while I enjoyed writing in C/C++ - it's not the most productive language for every task. Eventually, the requirements for our product pushed me to getting Gecko built and integrated with Gtk+ in windows. This was a huge effort and as before the benefits to me were small. After working more and more with the Gecko platform I realized it would do everything I needed. Plus it integrated very nicely in both Mac and Windows platforms (the primary targets of our consumer base). This drove me to rethink how I was building our application and to ultimately drop Gtk+ as our platform and transition completely over to C++/Javascript in the Xulrunner platform. Finally, after 14 months 10 of which we spent on Gtk+ and 4 with XUL we had released a product. Now at my new job we have done almost the same exact thing, but in the web space. We started down the path of trying to use Java, spending months on SOAP interfaces that ulitmately didn't meet the product requirements to in a very short time 6 months, standing up an entire sweet of applications using Ruby and Javscript. I guess what I'm trying to say is don't kill yourself getting Gtk+ working in windows, it won't be easy... If windows is your target, try something windows focused. For cross platform, I'd say either go web based or go XulRunner... Anyways, just my story and my 2 cents. Good Luck!

2007-02-11 4:46 am


I haven't had any problems USING gtk+ on win32 - in fact the mingw stock builds work better than fine (even mixing C runtimes doesn't seem to phase it) The point of building it on msvc is to get around mixing C runtimes - since I'm building php and php-gtk2 (a wrapper for gtk+ which makes working with it fabulous and fast - with all the pluses of php :) with MSVC 2005 which uses a different C runtime. I don't actually use C/C++ with Gtk+ - YUCK ;) But with php-gtk2 (like pygtk) you can have an app up and running in five minutes. Web-based is not always the right fit for an application. What happens when you have no internet access? And the problems with an xul/gecko based app is it will have all the weaknesses inherent with mozilla/gecko (can we say strange memory leaks from hell? Don't try to run an xulbased app overnight on windows...)

2007-02-11 12:52 pm


you should get the paying version of visual studio .net, I think the basic versions is around $100. It makes things easier and it comes with a lot of stuff for learning. you might even end up switching from php to C++ or .Net! Native Windows apps arent' really that bad to write.

2007-02-24 9:20 am


The very basic edition costs $299.00 - I don't know about you but I don't have almost three hundred dollars to throw around just to build open source windows apps.rnrnI've been learning quite a bit of C and C++ but they lose in two important areas - time to develop and cross-platform deployment. I can write it with php-gtk and run it on OS/2 if I'm nuts enough. I don't have to compile my program either...the strong point of a scripting language. It has less to do with "Native Windows apps are hard" and more to do with "I can write a php app in a day - and I don't have to compile it so it runs on my mac and my linux box and my Winxp machine and the old win98 machine..."

2007-02-24 7:23 pm


> It has less to do with “Native Windows apps are hard” and more to do rn> with “I can write a php app in a day - and I don’t have to compile it so rn> it runs on my mac and my linux box and my Winxp machine and the old rn> win98 machine…rnrnok I thought it was “Native Windows apps are hard” but if not more power to you... ;)

2007-03-08 4:52 pm

Post a Reply