ruby 错误:安装 ffi 时出错:错误:无法构建 gem 本机扩展
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7852566/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ERROR: Error installing ffi: ERROR: Failed to build gem native extension
提问by user1007520
Got the DevKit installed and re-ran the ffi install….got this as an output:
安装了 DevKit 并重新运行 ffi install ....得到这个作为输出:
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
_________________________________________________________________________________
Not sure how to deal with this issue. Kindly help.
不知道如何处理这个问题。请帮忙。
回答by ElS arekh
The gem install ffi fails due to the gem trying to build a bundled copy of libffi, which does not work due to assumptions that /usr/bin/env exists and too old libffi copy.
由于 gem 尝试构建 libffi 的捆绑副本,gem install ffi 失败,由于假设 /usr/bin/env 存在且 libffi 副本太旧,该副本不起作用。
However, you can build the ffi gem against the system libffi - install the packages:
但是,您可以针对系统 libffi 构建 ffi gem - 安装软件包:
apt install clang make ruby-dev libffi-dev
After that the ffi gem should build:
之后,ffi gem 应该构建:
gem install ffi
回答by tommasop
Version 1.0.10 has issues compiling on windows.
1.0.10 版在 Windows 上编译存在问题。
You can use the 1.0.9
您可以使用 1.0.9
gem install ffi --version='1.0.9'
回答by sahilbathla
sudo apt-get install libffi-dev
This worked for me
这对我有用
回答by DVG
Note that installing version 1.0.9 isn't going to be enough if your bundler keeps trying to go out and grab the latest version. In your gemfile you'll also want to put:
请注意,如果您的打包程序不断尝试获取最新版本,则安装 1.0.9 版本是不够的。在您的 gemfile 中,您还需要放置:
gem 'ffi', '1.0.9'
This should satisfy the dependency for whatever gem is asking for it and let you get up and running.
这应该满足对任何 gem 要求的依赖,并让您启动并运行。
回答by Grinn
For me the fix was running in this order. I'm not sure what all was relevant, but it worked:
对我来说,修复程序按此顺序运行。我不确定所有相关的内容,但它有效:
gem install ffi --version '1.0.9'
The above failed, but then I could successfully run:
以上失败,但后来我可以成功运行:
gem install bundler
...and subsequently:
...随后:
gem install ffi
...which got the latest version (1.6.0 at the time of writing this) and installed it successfully.
...获得了最新版本(撰写本文时为 1.6.0)并成功安装。
回答by maniempire
when the above steps are followed, it might results the following message.
执行上述步骤后,可能会出现以下消息。
$ 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`
In that case, you can run the 'bundle update ffi' command and the error will be solved.
在这种情况下,您可以运行“bundle update ffi”命令,错误将得到解决。
回答by wantrapreneur
Installing the 'osx-gcc-installer' worked for me: (osx 10.8)
安装“osx-gcc-installer”对我有用:(osx 10.8)
回答by Cosmo Arun
you need this,
你需要这个,
apt-get install ruby2.2-dev
回答by David Vezzani
Copied from another post:
复制自另一个帖子:
As stated in Issue with installing ImageMagick and rmagick on Mountain Lion, ffi appears to be configured to look for 'gcc-4.2', so once I updated my Apple command line tools(which I may or may not have needed to do), I created a symbolic link to make the ffi install configuration happy:
正如在 Mountain Lion 上安装 ImageMagick 和 rmagick 的问题中所述,ffi 似乎被配置为查找“gcc-4.2”,所以一旦我更新了我的Apple 命令行工具(我可能需要也可能不需要这样做),我创建了一个符号链接以使 ffi 安装配置满意:
sudo ln -s /usr/bin/gcc /usr/bin/gcc-4.2
回答by vovan
Helped me:
帮助过我:
sudo apt install build-essential
Debian 9
Debian 9
Ruby 2.3.3
红宝石 2.3.3

