Subject:
[ruby-ffi] Re: Error trying to install ffi
From:
Michael Cohen
Date:
11/10/11 6:16 PM
To:
ruby-ffi

Okay, I found the problem and it has to do with Ruby's mkmf gem. The
issue
is when you try to build a C extension. The mkmf generates a Makefile
to confirm a clean compile, such as the following:

"/usr/bin/gcc-4.2 -o conftest -I/Users/fc/.rvm/rubies/ruby-1.9.2-
p290/
include/ruby-1.9.1/x86_64-darwin11.0.0 -I/Users/fc/.rvm/rubies/
ruby-1.9.2-p290/include/ruby-1.9.1/ruby/backward -I/Users/fc/.rvm/
rubies/ruby-1.9.2-p290/include/ruby-1.9.1 -I. -D_XOPEN_SOURCE -
D_DARWIN_C_SOURCE    -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-
parentheses -Wpointer-arith -Wwrite-strings -Wno-missing-field-
initializers -Wshorten-64-to-32 -Wno-long-long  -fno-common -pipe
conftest.c  -L. -L/Users/fc/.rvm/rubies/ruby-1.9.2-p290/lib -L.
-
lruby.1.9.1-static  -lpthread -ldl -lobjc "
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main() {return 0;}
/* end */

The problem is that it's trying to make use of gcc-4.2. However, if
you have xcode 4.2 installed there is no gcc-4.2. Rather you have
llvm-
gcc-4.2 installed in the /usr/bin directory. The moment you change
gcc-4.2 to llvm-gcc-4.2 everything works. This will have to be
brought
up with the core Ruby team. If you have xcode 4.1 installed prior and
did not uninstall it then you will also have gcc-4.2 installed.

In any case, you can quickly resolve the problem by simply creating a
symbolic link to llvm-gcc-4.2 to be gcc-4.2 in the /usr/bin
directory.
Then when you go ruby extconf.rb the ffi C extension will compile
cleanly.

-Mike

On Nov 10, 10:43 am, Michael Cohen <michael.lee.co...@gmail.com>
wrote:
> Hi,
>
> I'm trying to install the ffi gem but when I run the gem install command I
> get the following error message:
>
> Building native extensions.  This could take a while...
> ERROR:  Error installing ffi:
> ERROR: Failed to build gem native extension.
>
>         /Users/frozencanuck/.rvm/rubies/ruby-1.9.2-p290/bin/ruby extconf.rb
> checking for ffi.h... *** 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.
>
> Any idea what is going on? I've tried to explicitly download v1.0.10 but I
> get the same error message.
>
> I'm using Ruby v1.9.2-p290 running on Mac OS X 10.7.2. I also have xcode
> 4.2 installed. Any meaningful thoughts on this would be appreciated.
>
> -Mike