tags:

views:

131

answers:

2

Hi,

I'm trying to install ruby-filemagic.

I tried sudo gem install ruby-filemagic -v 0.2.2 and got:

ERROR:  Error installing ruby-filemagic:
ERROR: Failed to build gem native extension.

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb
checking for magic_open() in -lmagic... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
 --with-opt-dir
 --without-opt-dir
 --with-opt-include
...

According to this : http://blog.elctech.com/2009/08/31/installing-ruby-filemagic-on-macos-x-and-ubuntu/

I need the opt-dir setting. Opt is for mac ports right? And I'm using homebrew.

Any suggestions as to where to go from here would be great.

Installing directly from the gem still didn't work for me but the following command did: sudo env ARCHFLAGS="-arch x86_64" gem install ruby-filemagic -- --with-magic-include=/usr/local/include --with-magic-lib=/usr/local/lib/

A: 

Yes, the commands from that tutorial are specific (in some ways) to MacPorts. The guide suggests first installing the necessary library via MacPorts, and then installing the gem that uses that library. At a glance, you don't have the library, so the extension can't be built for the gem. Also at a quick glance, Homebrew doesn't appear to have that library available for installation - though I'm not 100% sure of that.

Follow-up: From the same blog, here's his advice for how to do it with Homebrew. In a nutshell, you need to create your own installation of the library you need and then you should be ok. By the way, he suggests sudo, but you probably don't need or want that with Homebrew (if you use Homebrew in the normal way).

Telemachus
+1  A: 

you don't have to make your own formula, it's there in libmagic.

brew install libmagic
brew link libmagic

then, for whatever reason the gem install didn't work but cloning the lib and running

ruby extconf
make
make install

worked. godspeed!

Michael Glass
brew install libmagic and brew link libmagic work great but ruby extconf is still getting upset. checking for magic_open() in -lmagic... no This has to be that ruby-filemagic doesn't know where to look. How can I tell it?