Subject:
[ruby-ffi] Re: Install ffi on Mac gives trouble with asm insert
From:
Wayne Meissner
Date:
7/23/12 5:27 PM
To:
ruby-ffi@googlegroups.com


Try ffi-1.1.1.rc2 (install with: gem install ffi --pre)


On Tuesday, 24 July 2012 05:19:20 UTC+10, Jim Clarke wrote:
The problem:  Installing ffi-1.1.0 on my Mac (system details below) produces
output including this error message:

---------
$ gem install ffi
Building native extensions.  This could take a while...
ERROR:  Error installing ffi:
        ERROR: Failed to build gem native extension.

        /Users/clarke/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb
checking for ffi_call() in -lffi... yes
checking for ffi_prep_closure()... yes
checking for ffi_raw_call()... yes
checking for ffi_prep_raw_closure()... yes
checking for rb_thread_blocking_region()... yes
checking for ruby_native_thread_p()... yes
checking for rb_thread_call_with_gvl()... yes
creating extconf.h
creating Makefile

make
[...]
compiling MethodHandle.c
MethodHandle.c:204: error: expected declaration specifiers or '...' before string constant
[...]
make: *** [MethodHandle.o] Error 1


Gem files will remain installed in /Users/clarke/.rvm/gems/ruby-1.9.3-p194/gems/ffi-1.1.0 for inspection.
Results logged to /Users/clarke/.rvm/gems/ruby-1.9.3-p194/gems/ffi-1.1.0/ext/ffi_c/gem_make.out
---------

Essentially the same error appeared with ffi-1.0.11. Given the line number,
it seems that the asm() insert is being rejected.

My system:
Mac OX X 10.7.4 (Lion)
Xcode 4.3.3
gcc: i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1

---------

Here are two changes, either one of which seems to allow make to run in the ext directory.
Both changes affect this line in ext/Makefile:

CFLAGS   = -fno-common -std=c99 -pedantic -Wall -fno-common -pipe -I/opt/local/lib/libffi-3.0.11/include   $(ARCH_FLAG)

First fix: remove -std=c99

or

Second fix: replace -std=c99 with -std=gnu99

Since I don't do much C programming on the Mac (and have never used asm in a
C program), and since I'm totally new to Ruby, I offer these fixes more as guesses
than as firm suggestions. However, Googling turned up one or two unresolved
queries about the same problem, so maybe I'm not alone?

I'd be a little unhappy to try becoming my own ffi expert. Any chance of a
more authoritative fix?