23 April 2008

Redland RDF library and Ruby

Ever wanted to use the Redland RDF library with Ruby? In case you do not know Redland, it's a library to manipulate RDF triples and perform SPARQL queries as needed for semantic web applications. Redland is written in C++ and provides bindings to other languages like Java or Ruby.

Although current version is 1.0.7, windows binaries are only available for 1.0.3. Ok, it's my fault, I could always compile the stuff myself, but as a true Java person, I try to stay away from such obscenities. (This is probably another argument for Joel that Java coders can't be real programmers).

So I took version 1.0.3 and hoped that everything would be fine. When testing some of its command line tools, it turned out that still some libraries were missing: msvcp71.dll and msvcr71.dll. This should have been a hint to me, obviously these files belong to Microsoft's Visual C++ 7.1, but I did not bother and was happy to find them online in some dll archive.

Bound But the Ruby binding still needed another library (read a dll) to run, which was nowhere to find. So I was forced to fool around with Devccp (Mingw) myself to compile it. Unfortunately Ruby's extconf.rb works only with MSVC, so the auto-generated make file was of little use. After a painful day I finally managed to compile the given redland_wrap.c into a nice little redland.dll.

So far so good. Redland's Ruby API looked easy and some unit tests showed the way. But why did some tests work and some failed with a segmentation fault. In fact, why did most Redland functions crash for URIs longer than 20 characters? So after 2 days wasted, this looked like obviously incomplete compilation or linkage problems.

You might think that the Mingw compiled code might not be fully compatible with Ruby's core libraries, which are supposed to be MSVC6 stuff on Windows systems. Well, there are some issues about this topic, but here it was not the case. Much later I was able to access an old MSVC6 installation and compile the Redland Ruby binding again. This time the Ruby's extconf.rb worked nicely and make produced a redland.so. Still the functions crashed the same.

In the end it turned out, that the Redland 1.0.3 binaries for Windows where compiled using Visual C++ .NET 2003 (aka VC 7.1) , which needs the dotNET 1.1 framework runtime, which I choose not to install. Couldn't the system tell me that some runtime dependency is missing instead of producing segmentation faults all the time?

In case you face similar problems, here are the results of my "hard" work:

No comments: