<?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>clog: Getting Ruby GD2 working on OSX</title>
    <link>http://blog.chrispcritter.com/articles/2006/11/26/getting-ruby-gd2-working-on-osx</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description></description>
    <item>
      <title>Getting Ruby GD2 working on OSX</title>
      <description>I installed the Ruby GD2 gem on my Mac last night and found myself getting the following error:
&lt;br /&gt;&lt;br /&gt;

ruby/gems/1.8/gems/gd2-1.1.1/lib/gd2.rb:59:in `initialize&amp;#8217;:RuntimeError: dlopen(libgd.2.dylib, 9): image not found
&lt;br /&gt;&lt;br /&gt;

It didn&amp;#8217;t take very long to figure out that OSX doesn&amp;#8217;t seem to come with any version of libgd.  After bouncing around with trying to get RMagick installed instead, and finding very little documentation on setting up the Ruby GD2 library, I decided to install the gd2 package via ports and reinstalled the gem with the same results.  It still wasn&amp;#8217;t finding libgd because the ports library path (/opt/local/lib) is not set in my path.  I don&amp;#8217;t set this because I want anything self-compiled to only use the Mac libraries.  After some digging, I found that I could  specify the path in the Ruby GD2 source.  
&lt;br /&gt;&lt;br /&gt;

To fix it I changed line 33 in &amp;#8220;ruby/gems/1.8/gems/gd2-1.1.1/lib/gd2.rb&amp;#8221; from:
&lt;br /&gt;&lt;br /&gt;
case Config::CONFIG[&amp;#8216;arch&amp;#8217;]&lt;br /&gt;
   when /darwin/&lt;br /&gt;
      &amp;#8216;libgd.2.dylib&amp;#8217;&lt;br /&gt;
&lt;br /&gt;
to:&lt;br /&gt;&lt;br /&gt;

case Config::CONFIG[&amp;#8216;arch&amp;#8217;]&lt;br /&gt;
  when /darwin/&lt;br /&gt;
    &amp;#8216;/opt/local/lib/libgd.2.dylib&amp;#8217;&lt;br /&gt;&lt;br /&gt;

It&amp;#8217;s not the cleanest fix, but it&amp;#8217;s good enough for development purposes.  Hopefully this saves a few people from some of the circles I went through figuring this out.  It does seem that this is a least a more simple fix than what&amp;#8217;s required to get the RMagick library running on OSX. 

</description>
      <pubDate>Sun, 26 Nov 2006 12:05:00 -0800</pubDate>
      <guid isPermaLink="false">urn:uuid:c53372e1-955e-4027-8104-3f3bd3dc0ca8</guid>
      <author>chrisp</author>
      <link>http://blog.chrispcritter.com/articles/2006/11/26/getting-ruby-gd2-working-on-osx</link>
      <category>Development</category>
      <category>Ruby and RubyOnRails</category>
      <category>Ruby</category>
      <category>OSX</category>
      <category>Mac</category>
      <category>GD2</category>
    </item>
    <item>
      <title>"Getting Ruby GD2 working on OSX" by Eric Pugh</title>
      <description>&lt;p&gt;I added a different hack that looks like this:&lt;/p&gt;

&lt;p&gt;#FIXME:  I changed this so that if the lib isn&amp;#8217;t found, then we use the 
  # hardcoded path as defined in the blog post
  # &lt;a href="http://blog.chrispcritter.com/articles/2006/11/26/getting-ruby-gd2-working-on-osx" rel="nofollow"&gt;http://blog.chrispcritter.com/articles/2006/11/26/getting-ruby-gd2-working-on-osx&lt;/a&gt;
  begin
    LIB = DL.dlopen(gd&lt;em&gt;library&lt;/em&gt;name)
  rescue RuntimeError
    LIB = DL.dlopen(&amp;#8216;/opt/local/lib/libgd.2.dylib&amp;#8217;)
  end&lt;/p&gt;

&lt;p&gt;That way if the regular one works, great!&lt;/p&gt;</description>
      <pubDate>Mon, 06 Oct 2008 11:59:15 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:8e6ba094-037a-421e-a4fc-7234e54e9d28</guid>
      <link>http://blog.chrispcritter.com/articles/2006/11/26/getting-ruby-gd2-working-on-osx#comment-59970</link>
    </item>
    <item>
      <title>"Getting Ruby GD2 working on OSX" by Eric Pugh</title>
      <description>&lt;p&gt;I added a different hack that looks like this:&lt;/p&gt;

&lt;p&gt;#FIXME:  I changed this so that if the lib isn&amp;#8217;t found, then we use the 
  # hardcoded path as defined in the blog post
  # &lt;a href="http://blog.chrispcritter.com/articles/2006/11/26/getting-ruby-gd2-working-on-osx" rel="nofollow"&gt;http://blog.chrispcritter.com/articles/2006/11/26/getting-ruby-gd2-working-on-osx&lt;/a&gt;
  begin
    LIB = DL.dlopen(gd&lt;em&gt;library&lt;/em&gt;name)
  rescue RuntimeError
    LIB = DL.dlopen(&amp;#8216;/opt/local/lib/libgd.2.dylib&amp;#8217;)
  end&lt;/p&gt;

&lt;p&gt;That way if the regular one works, great!&lt;/p&gt;</description>
      <pubDate>Mon, 06 Oct 2008 11:57:02 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:96f542d0-0ccc-401f-8860-f248dcacb0ae</guid>
      <link>http://blog.chrispcritter.com/articles/2006/11/26/getting-ruby-gd2-working-on-osx#comment-59969</link>
    </item>
    <item>
      <title>"Getting Ruby GD2 working on OSX" by Yasuko</title>
      <description>&lt;p&gt;I was saved! This article was the only one I found about my trouble. Thank you very match.&lt;/p&gt;</description>
      <pubDate>Mon, 29 Sep 2008 06:01:46 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:c8db8faa-a1bb-4515-9e14-87806d93ce6c</guid>
      <link>http://blog.chrispcritter.com/articles/2006/11/26/getting-ruby-gd2-working-on-osx#comment-56568</link>
    </item>
    <item>
      <title>"Getting Ruby GD2 working on OSX" by scott</title>
      <description>&lt;p&gt;got rid of my pain - thanks for the article and the comments - I used a symlink.  didn&amp;#8217;t fully understand the LDPATH solution but interested to learn more.  thanks&amp;#8230;scott&lt;/p&gt;</description>
      <pubDate>Fri, 16 May 2008 08:39:18 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:845db9b2-562b-43c0-811b-cd42395a49b6</guid>
      <link>http://blog.chrispcritter.com/articles/2006/11/26/getting-ruby-gd2-working-on-osx#comment-42479</link>
    </item>
    <item>
      <title>"Getting Ruby GD2 working on OSX" by freegenie</title>
      <description>&lt;p&gt;I found it quick and useful, thanks.&lt;/p&gt;</description>
      <pubDate>Fri, 28 Mar 2008 08:57:01 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:9de6c913-ba4b-4dac-9eca-5bd4d92bc916</guid>
      <link>http://blog.chrispcritter.com/articles/2006/11/26/getting-ruby-gd2-working-on-osx#comment-38504</link>
    </item>
    <item>
      <title>"Getting Ruby GD2 working on OSX" by kennon</title>
      <description>&lt;p&gt;I think the better solution would be for the library to check LDPATH, and then you could add /opt/local/lib to LDPATH.&lt;/p&gt;</description>
      <pubDate>Wed, 11 Apr 2007 03:45:41 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:3d6bbe80-e40c-4e04-acfc-ee387596a173</guid>
      <link>http://blog.chrispcritter.com/articles/2006/11/26/getting-ruby-gd2-working-on-osx#comment-80</link>
    </item>
    <item>
      <title>"Getting Ruby GD2 working on OSX" by krafthus.dk</title>
      <description>&lt;p&gt;Rather than having to edit the gem, I find it cleaner to just symlink the library from /usr/lib:&lt;/p&gt;

&lt;p&gt;flake:/usr/lib morten$ sudo ln -s /opt/local/lib/libgd.2.dylib &lt;/p&gt;</description>
      <pubDate>Wed, 28 Feb 2007 06:15:17 -0800</pubDate>
      <guid isPermaLink="false">urn:uuid:d1c7ef0b-1c3b-4a2e-b280-cd61d4cc4b9a</guid>
      <link>http://blog.chrispcritter.com/articles/2006/11/26/getting-ruby-gd2-working-on-osx#comment-5</link>
    </item>
  </channel>
</rss>
