Archive for August, 2009

Getting qt4-qtruby-2.0.3 running on Mac OS X (and Qt)

Posted in Development, Software on August 21, 2009 by osake


Please bear with me to share a little history of how I even got an interest in trying Ruby/Qt on the Mac.

In the past I’ve tried to learn GUI development.  The biggest roadblock (aside from the learning curve) was getting one installed with all its dependencies.  And maybe I’m asking for it when developing on a Mac.  They’ve always been company provided, so I’m not going to whine too much.

Some time ago, I co-presented on a GUI toolkit talk at my Ruby user group (KCRUG).  My compatriots chose Ruby Cocoa and Gtk, while I chose Shoes (I miss you _why).  I wasn’t just chosing Shoes to be eclectic, but I wanted ease of cross-platform.  Shoes to me also seemed easier to get up and running at the time.

So now, you should understand where I’m coming from.  I want cross-platform and I want something simple to setup.  Well, unfortunately, my portion of the presentation was a fail.  Not the presentation itself, but I was unable to get what I needed to talk to Wee War’s site and do anything.  Even with an excellent Wee War API wrapper in Ruby done up by Sean.

Shoes (still young at the time) wasn’t going to float for me any longer.  It did receive constant love from contributors to the source, but the struggle for me to achieve anything on par with the excellent sample apps ruined my glorious vision of triumph with a simple, elegant tool.  Someone recently gave me their thoughts on why Shoes failed me, and maybe its true.  I just couldn’t adapt my comprehension of programming to the Shoes DSL.

Gtk and Cocoa.  Well, let’s just dump Cocoa now, I had no interest in limiting myself.  So after that presentation (which mind you, was done in an Ubuntu VM), I tried to fire up the whole Ruby/Gtk thing native on the Mac.  After flailing for a few days, I caved in and abandoned my search for some time.


Well, a little more history, but relevant to the post topic.  Something recently spurred my interest in Qt.  I’ll be the first to admit that I’ve always used Gnome, Windows, or Mac for my windowing system.  I do occasionally boot Knoppix, but I really don’t get too deep into Qt stuff.  Oh yeah, and I’ve used/currently use many things that have their claim to fame in Qt.

I tried hitting up TrollTech to get started.  No go, the link I found was dead with no redirect or anything.  A quick search clued me in to Nokia’s recent involvement.  This is fine by me, there is still an LGPL version and now it’s funded love.

Let’s review real quick, my requirements: must be cross-platform, I’d like to do it in Ruby if possible, and I have to be able to get it working natively on my Mac.


As of this post, here is what I had to grab (oh yeah, you’ll need Xcode I’m pretty sure, comes with your Mac though)

  • Qt (4.5.2 from Nokia)
  • cmake (2.6.4 from cmake)
  • ruby (1.8.6, compiled version of Ruby)
  • qt4-qtruby-2.0.3 (2.0.3 from RubyForge)

I installed Ruby first since I do that professionally.  Qt was next, and I actually went with the full SDK in case I want to explore outside the realm of Ruby, or find limitations or interests that take me back to C++.   I then made the mistake of trying to just build qt4-qtruby.  You need cmake to build it, so get cmake up and running.  I actually used the binary dmg and linked it up in my shell path during installation.

Now, just so you don’t spend a lot of time asking why cmake in the source dir fails, let’s get you on the right foot off the bat.

$ cmake -Wno-dev \
-DRUBY_INCLUDE_PATH=/usr/lib/ruby/1.8/universal-darwin9.0 \
-DRUBY_LIBRARY=/usr/lib/libruby.1.dylib \

You may need to change your Ruby paths, but the other options will help get you through cmake and make.

I saw a more detailed build on phosphorescence‘s blog, but my cmake params should suffice.

After cmake is complete:

$ make && sudo make install

Feel free to break that up, but I just like getting it all done in one pass.

The next headache that plagued me over night and into the morning was that my build was successful, but I was unable to complete the ‘helloworld’ example.

require 'Qt4'

app =

hello ='Hello World!')
hello.resize(100, 30)


Line 1 was throwing a LoadError exception for ‘qtruby4’.  I am not terribly good at figuring this sort of thing out.  I mean, I know what it’s saying, but I don’t understand why.  To my knowledge everything was done correctly.  I spent several hours in IRC and searching forums last night.

I came across a German post which Google tried to help me with it’s translation, but I didn’t quite grasp what the fellow was saying.  At this point, I tried a few things before going to sleep and eventually gave in to the sand man.

The next day, I popped in IRC and low and behold, Richard Dale himself was there.  A short while after summarizing my issue, he blessed me with the answer.  For my installation:

$ cd /Library/Ruby/Site/1.8/universal-darwin9.0
$ ln -s qtruby4.bundle

So really, just change to whatever directory contains your compiled qtruby4 library and create the symlink to qtruby4.bundle.  Go figure.  I’m tempted to spend a little time understanding what these .bundle files are, but that’s another story.