9.12.08

wxruby: reading error messages about libraries

As you might have noticed, some time has passed since I wrote about fxruby. Wxruby was to follow a few days after it. However I had been experiencing problems getting it to work. With only a few days to go before the Shoes class starts I wanted to put an end to this misery.

First thing people do nowadays when problem solving is to Google for solutions, so did I. Searching for the errors I got did return some mailing list postings from people with the same problem, but no useful answers. As you might have experienced yourself, searching for these kinds of things can quickly take hours without you realizing it. It is not only time consuming, but in the spirit of despair you might just actually try some really stupid recommendation from a person who's most likely just be guessing himself. Actually trying some of their suggestions can add even more problems and make the whole so complex you'll eventually just give up...but then that's not very Ninja, is it?

After installing the wx package I thought I'd only need to install the wxruby gem and be done with it.

sudo gem install wxruby

Unfortunately not so...
ruby -rubygems ./wxtest.rb
/var/lib/gems/1.8/gems/wxruby-1.9.9-x86-linux/lib/wxruby2.so: libwx_gtk2u_stc-2.8.so.0: cannot open shared object file: No such file or directory - /var/lib/gems/1.8/gems/wxruby-1.9.9-x86-linux/lib/wxruby2.so (LoadError)
from /usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in `require'
from /var/lib/gems/1.8/gems/wxruby-1.9.9-x86-linux/lib/wx.rb:12
from /usr/lib/ruby/1.8/rubygems/custom_require.rb:32:in `gem_original_require'
from /usr/lib/ruby/1.8/rubygems/custom_require.rb:32:in `require'
from ./wxtest.rb:3
Obviously it had some problems loading the wxruby2.so binary library. This file exists in the specified directory along with wx.rb. The permissions to wxruby2.so were set to readonly, this did not seem right for a binary. Adding execute permissions did not help however.

The problem might have been caused by one of the other errors. One of them seemed to originate from wx.rb. Wx.rb can be found in the same directory as wxruby2.so. This is the file you should require in your ruby code. Basically it loads both the wxruby2.so and ruby extensions to core wx classes. There was something about line 12. Using vim's :set nu command, the apparent culprit was displayed on my screen:
11 # load the binary library
12 require 'wxruby2'
13
14 # alias the module
15 Wx = Wxruby2
There could not be anything wrong about that.

There were however three errors in custom_require.rb. The first impression was, judging from the directory, that this was a generic function used by or for rubygems. Obviously I was not very convinced that this might be the cause of the problem. But it would not hurt to take a look.

First look was at the code near line number 27:
26 def require(path) # :nodoc:
27 gem_original_require path
28 rescue LoadError => load_error
29 if load_error.message =~ /\A[Nn]o such file to load -- #{Regexp.escape path}\z/
Hmm, this code wants a path to some gem thingy, else it throws an error. Not the error I got however. While this seemed illogical at that moment, sometimes one must keep problems simple and not add other problems along the way. The main point was this code wanted some path.

Two other errors were caused at something near line 32.
32 gem_original_require path
33 else
34 raise load_error
No more clues were necessary. The suspect was some unknown path variable. Since wxruby was installed as a gem. My code needed to load rubygems itself. According to the installation manual there's three ways to do this:

* Run ruby with the -rubygems argument: eg ruby -rubygems my_wxruby_script.rb
* Set the RUBYOPT environment variable to -rubygems
* Add require 'rubygems' at the top of your wxruby program.

I had tried running my code with the -rubygems argument allready. And I did use the require 'rubygems' in my code. I did not set the RUBYOPT however, so I removed the require line and set this variable with RUBYOPT="-rubygems".

The same errors lit the screen after I ran my code again. A sense of defeat and disillusion filled my mind, what could be the problem? I had tried countless solutions, analyzed code, read documentation and yet I was no step further. Having no more ideas, I stared blankly at the screen, looking at the errors...

/var/lib/gems/1.8/gems/wxruby-1.9.9-x86-linux/lib/wxruby2.so: libwx_gtk2u_stc-2.8.so.0: cannot open shared object file: No such file or directory - /var/lib/gems/1.8/gems/wxruby-1.9.9-x86-linux/lib/wxruby2.so (LoadError)

Staring back was a half lit reflection of myself. I saw a person who was about to give up as I started to think about skipping this chapter of the GUI Toolkit extravaganza. At least I had Ruby-GTK2 and FXruby...GTK?...What's that gtk doing in my error message!

A quick query in my package management tool found that I did not have any libwx_gtk* libraries installed, why would I. The documentation certainly did not write about needing this library! I did encounter it while searching for ruby & wx libraries, but never made the connection...

Anyway, there were some dependencies and here's what was installed:

libwxgtk2.6-0
libwxgtk2.6-dev
libwxbase2.6-0
libwxbase2.6-dev
libwxgtk2.8-0
libwxgtk2.8-dev
libwxbase2.8-0
libwxbase2.8-dev

After this I could run the examples that come with wxruby. Looking back at the errors I wonder, did you overlook this one in the error messages as well?

Comming up: Part III of the GUI toolkit extravaganza, featuring wxruby!

1 comment:

allan316 said...

thank you wise ninja, i was stumped with these errors till i read your blog entry.