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

安装了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 fh\" -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 _________________________________________________________________________________ 

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

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

你可以使用1.0.9

 gem install ffi --version='1.0.9' 
 sudo apt-get install libffi-dev 

这对我有用

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

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

 apt install clang make ruby-dev libffi-dev 

之后,ffi gem应该构建:

 gem install ffi 

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

 gem 'ffi', '1.0.9' 

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

按照上述步骤操作时,可能会产生以下消息。

 $ 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’命令,错误将被解决。

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

 gem install ffi --version '1.0.9' 

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

 gem install bundler 

……随后:

 gem install ffi 

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

安装’osx-gcc-installer’对我有用:(osx 10.8)

https://github.com/kennethreitz/osx-gcc-installer/downloads

你需要这个,

 apt-get install ruby2.2-dev 

从另一篇文章复制:

正如在Mountain Lion上安装ImageMagick和rmagick的问题所述,ffi似乎被配置为寻找’gcc-4.2’,所以一旦我更新了我的Apple命令行工具 (我可能需要或可能不需要这样做),我创建了一个符号链接,使ffi安assembly置更加快乐:

 sudo ln -s /usr/bin/gcc /usr/bin/gcc-4.2 

将DevKit放在PATH前面,然后从Windows命令提示符重新安装。

我遇到了同样的问题。 就我而言,我还没有安装DevKit,可以找到: http ://rubyinstaller.org/downloads/。 安装DevKit后,只需按照说明https://github.com/oneclick/rubyinstaller/wiki/development-kit进行操作 ,最后启动并运行。

我不得不安装automake以使其正常工作。 适用于mac OSX和Ubuntu(CI机器)。