错误: 安装ffi时出错:错误: 无法构建本地宝石扩展。

32

我已安装了DevKit并重新运行了ffi安装程序...得到以下输出:

C:\Documents and Settings\******>gem install ffi
Temporarily enhancing PATH to include DevKit...
Building native extensions.  This could take a while...
ERROR:  Error installing ffi:
        ERROR: Failed to build gem native extension.

        C:/Ruby192/bin/ruby.exe extconf.rb
checking for ffi.h... no
checking for ffi.h in /usr/local/include... no
checking for rb_thread_blocking_region()... yes
checking for ruby_thread_has_gvl_p()... yes
checking for ruby_native_thread_p()... yes
checking for rb_thread_call_with_gvl()... yes
creating extconf.h
creating Makefile
make
C:/Ruby192/bin/ruby -e "puts 'EXPORTS', 'Init_ffi_c'"  > ffi_c-i386-mingw32.def
gcc -I. -IC:/Ruby192/include/ruby-1.9.1/i386-mingw32 -I/C/Ruby192/include/ruby-1
.9.1/ruby/backward -I/C/Ruby192/include/ruby-1.9.1 -I. -DRUBY_EXTCONF_H=\"extcon
f.h\"    -O3 -g -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -
Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-declaration-a
fter-statement   -o AbstractMemory.o -c AbstractMemory.c
In file included from AbstractMemory.c:28:0:
compat.h:65:20: warning: extra tokens at end of #ifndef directive
compat.h:69:24: warning: extra tokens at end of #ifndef directive
In file included from AbstractMemory.h:29:0,
                 from AbstractMemory.c:29:
Types.h:68:17: fatal error: ffi.h: No such file or directory
compilation terminated.
make: *** [AbstractMemory.o] Error 1 

Gem files will remain installed in C:/Ruby192/lib/ruby/gems/1.9.1/gems/ffi-1.0.1
0 for inspection.
Results logged to C:/Ruby192/lib/ruby/gems/1.9.1/gems/ffi-1.0.10/ext/ffi_c/gem_m
ake.out
_________________________________________________________________________________

我不确定如何处理这个问题。请帮忙。

17个回答

23
gem install ffi失败是因为试图构建一个捆绑的libffi副本,而该副本不起作用,原因是它假定/usr/bin/env存在并且libffi版本过旧。不过,你可以针对系统的libffi构建ffi gem - 安装以下软件包:
apt install clang make ruby-dev libffi-dev

然后 ffi 宝石应该构建:

gem install ffi

macOS怎么样? - Christian Vincenzo Traina

17
sudo apt-get install libffi-dev

这对我起作用了


这也是在Linux Mint系统上对我有效的方法。这里有一个提示给未来的搜索者(对于后人是否有用不得而知):根据我的经验,一个无法自动安装的gem通常需要使用系统自带的软件包管理器来安装相关软件包的“dev”版本。 - Jon Carter

16

版本1.0.10在Windows上编译存在问题。

您可以使用1.0.9版本。

gem install ffi --version='1.0.9'

+1 非常感谢,这帮助我在我的Win7电脑上安装了Middleman。 - Jason
ERROR: Error installing railties: ERROR: Failed to build gem native extension. - user1999510
错误是否发生在与 Windows 操作系统相同的 Ruby 和 FFI 版本? - tommasop

8
对我来说,解决方法是按照以下顺序运行。我不确定所有的内容是否都相关,但它起作用了:
gem install ffi --version '1.0.9'

上述方法失败了,但是随后我成功地运行了以下代码:
gem install bundler

...并随后:

gem install ffi

......在撰写本文时已经获得了最新版本(1.6.0),并成功安装了它。


非常感谢! - Salma Gomaa

7
当遵循上述步骤时,可能会出现以下消息。
$ bundle install
Fetching source index for https://rubygems.org/
You have requested:
ffi = 1.0.9

The bundle currently has ffi locked at 1.0.11.
Try running `bundle update ffi`

在这种情况下,您可以运行“bundle update ffi”命令,问题就会得到解决。

bundle update ffi 对我有用,谢谢。 - José Mateus

6
请注意,如果你的捆绑器一直尝试获取最新版本,那么安装1.0.9版本是不够的。在你的gemfile中,你还需要加入以下内容:
gem 'ffi', '1.0.9'

这样就可以满足需要它的任何gem的依赖关系,让您能够快速启动。


4

帮助了我:

sudo apt install build-essential

Debian 9

Ruby 2.3.3


4
对我来说,通常这样做可以解决问题。
gem install ffi -- --disable-system-libffi

2
这在单独安装 gem 时有效,但如果通过 bundle install 安装 ffi 则无效。 - Grant Birchmeier

4

1
问题所使用的环境是Windows。 - tommasop
2
较新版本的macOS可能只需执行xcode-select --install即可获取编译器。 - vhs
这个链接无法使用。 - Shamsul Haque

3

您需要这个:

apt-get install ruby2.2-dev

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接