<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Depth-First: Tag mkmf</title>
    <link>http://depth-first.com/articles/tag/mkmf</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>Walking the Web of Chemical Informatics</description>
    <item>
      <title>Painless Installation of Ruby Open Babel</title>
      <description>&lt;p&gt;&lt;a href="http://openbabel.sf.net"&gt;&lt;img src="http://depth-first.com/files/Babel256.png" align="right" border="0"&gt;&lt;/img&gt;&lt;/a&gt;&lt;a href="http://openbabel.sf.net"&gt;Open Babel&lt;/a&gt; 2.1.0 has just been &lt;a href="http://downloads.sourceforge.net/openbabel/openbabel-2.1.0.tar.gz?modtime=1175958364&amp;amp;big_mirror=0"&gt;released&lt;/a&gt;. Among its new features is a Ruby interface containing most of the functionality of the C++ library. Installation is quick and easy, as shown in this article.&lt;/p&gt;

&lt;h4&gt;Prerequisites&lt;/h4&gt;

&lt;p&gt;In addition to a working build system, you'll need &lt;a href="http://www.ruby-lang.org/en/"&gt;Ruby&lt;/a&gt; and the Ruby development libraries. Although any recent version should do, this tutorial was written with version 1.8.5.&lt;/p&gt;

&lt;h4&gt;Step 0: Compile and Install Open Babel&lt;/h4&gt;

&lt;p&gt;Given the right tools on your system, compiling and and installing Open Babel from source is trivial. &lt;a href="http://openbabel.sourceforge.net/wiki/Get_Open_Babel"&gt;This page&lt;/a&gt; gives instructions for doing so on Linux, Windows, and Mac OS X.&lt;/p&gt;

&lt;h4&gt;Step 1: Create the Wrapper's Makefile&lt;/h4&gt;

&lt;p&gt;After unpacking, compiling, and installing Open Babel, change into the &lt;strong&gt;scripts/ruby&lt;/strong&gt; directory of your source distribution. Next, run the &lt;strong&gt;extconf.rb&lt;/strong&gt; script:&lt;/p&gt;

&lt;div class="console"&gt;
&lt;pre&gt;
$ ruby extconf.rb
checking for main() in -lopenbabel... yes
creating Makefile
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;As you've probably guessed, the purpose of this script is to generate a Makefile specific to your platform. This script uses the standard Ruby library &lt;a href="http://www.ruby-doc.org/stdlib/libdoc/mkmf/rdoc/index.html"&gt;mkmf&lt;/a&gt;.&lt;/p&gt;

&lt;h4&gt;Step 2: Compile the Wrapper&lt;/h4&gt;

&lt;p&gt;After creating a Makefile, we're ready to compile the C++ Ruby wrapper, contained in &lt;strong&gt;openbabel_ruby.cpp&lt;/strong&gt;:&lt;/p&gt;

&lt;div class="console"&gt;
&lt;pre&gt;
$ make
g++ -I. -I. -I/usr/lib/ruby/1.8/x86_64-linux-gnu -I. -I../../include  -fPIC -O2 -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -Wall  -fPIC   -c openbabel_ruby.cpp
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;This output will be followed by other lines as the compiler builds the wrapper library.&lt;/p&gt;

&lt;h4&gt;Step 3: Install the Wrapper&lt;/h4&gt;

&lt;p&gt;After compiling the wrapper, we're ready to install it. You can probably guess that the next command will be (as root):&lt;/p&gt;

&lt;div class="console"&gt;
&lt;pre&gt;
# make install
/usr/bin/install -c -m 0755 openbabel.so /usr/lib/ruby/site_ruby/1.8/x86_64-linux-gnu
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Your install directory is chosen by Ruby to be appropriate for your platform and Ruby version.&lt;/p&gt;

&lt;h4&gt;Hello, Benzene!&lt;/h4&gt;

&lt;p&gt;Congratulations, you've installed Ruby Open Babel! You can verify that your new library works with interactive Ruby (irb):&lt;/p&gt;

&lt;div class="console"&gt;
&lt;pre&gt;
$ irb
irb(main):001:0&gt; require 'openbabel'
=&gt; true
irb(main):002:0&gt; c=OpenBabel::OBConversion.new
=&gt; #&amp;lt;OpenBabel::OBConversion:0x2acedbadd020&amp;gt;
irb(main):003:0&gt; c.set_in_format 'smi'
=&gt; true
irb(main):004:0&gt; benzene=OpenBabel::OBMol.new
=&gt; #&amp;lt;OpenBabel::OBMol:0x2acedbacfa10&amp;gt;
irb(main):005:0&gt; c.read_string benzene, 'c1ccccc1'
=&gt; true
irb(main):006:0&gt; benzene.num_atoms
=&gt; 6
&lt;/pre&gt;
&lt;/div&gt;</description>
      <pubDate>Mon, 09 Apr 2007 10:09:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:a3e7148e-96de-416a-996f-a8c7d7289531</guid>
      <author>Rich Apodaca</author>
      <link>http://depth-first.com/articles/2007/04/09/painless-installation-of-ruby-open-babel</link>
      <category>Tools</category>
      <category>ruby</category>
      <category>rubyopenbabel</category>
      <category>obruby</category>
      <category>openbabel</category>
      <category>mkmf</category>
    </item>
  </channel>
</rss>
