Monday, May 7, 2012

Installing wxRuby for Ubuntu

WxRuby is required for the Piping and Instrumentation Diagram (Piping) example in Enso, but it is no mean feat to install this Ruby gem under Ubuntu. The blame might possibly be split between a project that was last updated in 2009 and a distro that is notorious for using unusual packages. This post is a record of what I did, primarily as a personal memory aid. If you found this document useful, or if know how to improve it, leave a comment.

1. Installing the pre-compiled gem does not work
The latest pre-compiled gem I found on the wxruby website is version 2.0.1, dated 2009. WX libraries appear to have changed since then (I don't know which version the gem was compiled under) so attempting to use this will result in a symbol error.
LoadError: /var/lib/gems/1.9.1/gems/wxruby-ruby19-2.0.1-x86-linux/lib/wxruby2.so: symbol _ZN16wxStyledTextCtrl7SendMsgEill, version WXU_2.8 not defined in file libwx_gtk2u_stc-2.8.so.0 with link time reference - /var/lib/gems/1.9.1/gems/wxruby-ruby19-2.0.1-x86-linux/lib/wxruby2.so
2. Required dependencies
To compile wxRuby, you will need:
  • WxRuby sources from their website (link)
  • Wx Gtk libraries (libwxgtk2.8-dev)
  • SWIG 1.3.38, a C++ wrapper (link, version 1.3.38)
  • Development versions for:
    • GLib (libglib2.0-dev)
    • Pango (libpango1.0-dev)
    • Gtk2 and Gtk3 dev libraries (libgtk2.0-dev, libgtk-3-dev)
If you are installing wxRuby for Enso, you will need the Ruby 1.9 version.

Note also that you need a fairly specific version for SWIG, which I needed to compile from source. Make sure to set up the path to run SWIG.

3. Environment variables
We want to ignore all the references to the openGL library, which are not availables in unicode version.

export WXRUBY_EXCLUDED=GLCanvas

WxRuby requires you to provide a version number, but as usual things are never easy:

~/Desktop/wxruby-2.0.1$ rake gem
rake aborted!
Cannot build a package without a version being specified
Create a version by running rake with WXRUBY_VERSION=x.x.x

~/Desktop/wxruby-2.0.1$ export WXRUBY_VERSION=2.0.1
~/Desktop/wxruby-2.0.1$ rake gem
rake aborted!
can't modify frozen String



Thankfully Ruby is a programmer-friendly scripting language. A quick trace locates the line in Ruby's source you can change to make things work:

/usr/lib/ruby/1.9.1/rubygems/version.rb:
190,191c190,191 
<     @version = version.to_s 
<     @version.strip!
--- 
>     @version = version.to_s.strip
>     #@version.strip!

This was the line I changed, but this is by no mean authoritative, and I immediately changed it back once I got wxRuby up and running. Caveat emptor.

4. Compiling and installing WxRuby
You may now compile wxRuby by running:

rake gem
sudo gem install


Make sure to uninstall any other version of wxruby, including the Ruby 1.8 version, before you install the new gem.

Test the installation using irb:

~/Desktop/wxruby-2.0.1$ irb
irb(main):001:0> require 'wx'
=> true


Alternatively, you may test this directly with Enso:

ruby applications/Piping/code/visualize.rb



No comments: