错误:安装ffi时出错:错误:无法构建gem原生扩展

use*_*520 17 ruby gem ffi

安装了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
_________________________________________________________________________________
Run Code Online (Sandbox Code Playgroud)

不知道如何处理这个问题.请帮助.

tom*_*sop 16

版本1.0.10在Windows上编译有问题.

你可以使用1.0.9

gem install ffi --version='1.0.9'
Run Code Online (Sandbox Code Playgroud)


小智 14

由于gem尝试构建libffi的捆绑副本,gem install ffi失败,由于假设/ usr/bin/env存在且过旧的libffi副本而无效.

但是,您可以针对系统libffi构建ffi gem - 安装包:

apt install clang make ruby-dev libffi-dev
Run Code Online (Sandbox Code Playgroud)

之后,ffi gem应该构建:

gem install ffi
Run Code Online (Sandbox Code Playgroud)


小智 12

sudo apt-get install libffi-dev
Run Code Online (Sandbox Code Playgroud)

这对我有用


DVG*_*DVG 7

请注意,如果您的捆绑包不断尝试外出并获取最新版本,那么安装1.0.9版本是不够的.在你的gemfile中你还要放:

gem 'ffi', '1.0.9'
Run Code Online (Sandbox Code Playgroud)

这应该满足任何宝石要求它的依赖性,让你起床和运行.


Gri*_*inn 6

对我来说,修复程序按此顺序运行.我不确定所有相关内容,但它有效:

gem install ffi --version '1.0.9'
Run Code Online (Sandbox Code Playgroud)

以上失败了,但后来我可以成功运行:

gem install bundler
Run Code Online (Sandbox Code Playgroud)

......以及随后:

gem install ffi
Run Code Online (Sandbox Code Playgroud)

...获得最新版本(编写本文时为1.6.0)并成功安装.


man*_*ire 5

遵循上述步骤时,可能会产生以下消息.

$ 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`
Run Code Online (Sandbox Code Playgroud)

在这种情况下,您可以运行'bundle update ffi'命令,错误将被解决.