使用本机扩展安装 ffi 1.12.2 失败

Installing ffi 1.12.2 with native extensions FAILED

在 运行 "gem install ffi" 并尝试在 MacOS 上安装它后,出现以下错误:

> $ gem install ffi 
> NOTE:Gem::Specification#rubyforge_project= is deprecated with no
> replacement. It will be removed on or after 2019-12-01.
> Gem::Specification#rubyforge_project= called from
> /Users/myuser/.gem/specifications/escape-0.0.4.gemspec:18. NOTE:
> Gem::Specification#rubyforge_project= is deprecated with no
> replacement. It will be removed on or after 2019-12-01.
> Gem::Specification#rubyforge_project= called from
> /Users/myuser/.gem/specifications/fuzzy_match-2.0.4.gemspec:17.
> NOTE: Gem::Specification#rubyforge_project= is deprecated with no
> replacement. It will be removed on or after 2019-12-01.
> Gem::Specification#rubyforge_project= called from
> /Users/myuser/.gem/specifications/i18n-0.9.5.gemspec:17. NOTE:
> Gem::Specification#rubyforge_project= is deprecated with no
> replacement. It will be removed on or after 2019-12-01.
> Gem::Specification#rubyforge_project= called from
> /Users/myuser/.gem/specifications/little-plugger-1.1.4.gemspec:18.
> NOTE: Gem::Specification#rubyforge_project= is deprecated with no
> replacement. It will be removed on or after 2019-12-01.
> Gem::Specification#rubyforge_project= called from
> /Users/myuser/.gem/specifications/logging-2.2.2.gemspec:18. NOTE:
> Gem::Specification#rubyforge_project= is deprecated with no
> replacement. It will be removed on or after 2019-12-01.
> Gem::Specification#rubyforge_project= called from
> /Users/myuser/.gem/specifications/open4-1.3.4.gemspec:16. NOTE:
> Gem::Specification#rubyforge_project= is deprecated with no
> replacement. It will be removed on or after 2019-12-01.
> Gem::Specification#rubyforge_project= called from
> /Users/myuser/.gem/specifications/escape-0.0.4.gemspec:18. NOTE:
> Gem::Specification#rubyforge_project= is deprecated with no
> replacement. It will be removed on or after 2019-12-01.
> Gem::Specification#rubyforge_project= called from
> /Users/myuser/.gem/specifications/fuzzy_match-2.0.4.gemspec:17.
> NOTE: Gem::Specification#rubyforge_project= is deprecated with no
> replacement. It will be removed on or after 2019-12-01.
> Gem::Specification#rubyforge_project= called from
> /Users/myuser/.gem/specifications/i18n-0.9.5.gemspec:17. NOTE:
> Gem::Specification#rubyforge_project= is deprecated with no
> replacement. It will be removed on or after 2019-12-01.
> Gem::Specification#rubyforge_project= called from
> /Users/myuser/.gem/specifications/little-plugger-1.1.4.gemspec:18.
> NOTE: Gem::Specification#rubyforge_project= is deprecated with no
> replacement. It will be removed on or after 2019-12-01.
> Gem::Specification#rubyforge_project= called from
> /Users/myuser/.gem/specifications/logging-2.2.2.gemspec:18. NOTE:
> Gem::Specification#rubyforge_project= is deprecated with no
> replacement. It will be removed on or after 2019-12-01.
> Gem::Specification#rubyforge_project= called from
> /Users/myuser/.gem/specifications/open4-1.3.4.gemspec:16. Building
> native extensions. This could take a while... ERROR:  Error installing
> ffi:  ERROR: Failed to build gem native extension.
> 
>     current directory: /Users/georgegoci/.gem/gems/ffi-1.12.2/ext/ffi_c
> /Users/myuser/.rbenv/versions/2.7.0/bin/ruby -I
> /Users/myuser/.rbenv/versions/2.7.0/lib/ruby/2.7.0 -r
> ./siteconf20200227-34272-rl7ya0.rb extconf.rb checking for ffi.h... no
> checking for ffi.h in /usr/local/include,/usr/include/ffi... no
> checking for shlwapi.h... no checking for
> rb_thread_call_without_gvl()... yes checking for
> ruby_native_thread_p()... yes checking for ruby_thread_has_gvl_p()...
> yes creating extconf.h creating Makefile
> 
> current directory: /Users/myuser/.gem/gems/ffi-1.12.2/ext/ffi_c
> make "DESTDIR=" clean
> 
> current directory: /Users/myuser/.gem/gems/ffi-1.12.2/ext/ffi_c
> make "DESTDIR=" Configuring libffi clang: error: unsupported option
> '-print-multi-os-directory' clang: error: no input files cd
> "/Users/myuser/.gem/gems/ffi-1.12.2/ext/ffi_c/libffi-x86_64-darwin18"
> && /Applications/Xcode 10_3.app/Contents/Developer/usr/bin/make
> /bin/sh: /Applications/Xcode: No such file or directory make: ***
> ["/Users/myuser/.gem/gems/ffi-1.12.2/ext/ffi_c/libffi-x86_64-darwin18"/.libs/libffi_convenience.a]
> Error 127
> 
> make failed, exit code 2
> 
> Gem files will remain installed in
> /Users/myuser/.gem/gems/ffi-1.12.2 for inspection. Results logged
> to
> /Users/myuser/.gem/extensions/x86_64-darwin-18/2.7.0/ffi-1.12.2/gem_make.out

我也尝试过这个解决方案:

  1. Gem install ffi Failed to build gem native extension
  2. Installing pg 1.1.3 with native extensions fails

但是还是没有解决。

有什么想法吗?

您日志中的相关错误是:

/bin/sh: /Applications/Xcode: No such file or directory

这是由于:

clang: error: no input files 
cd "/Users/myuser/.gem/gems/ffi-1.12.2/ext/ffi_c/libffi-x86_64-darwin18" && /Applications/Xcode 10_3.app/Contents/Developer/usr/bin/make

ffi 的 makefile 可能不支持命令行工具路径中的空格。您应该重命名您的 Xcode 名称并确保 xcode-select -p 指向没有空格的更新路径。

这个答案可能与您不再相关,但我花了很长时间才在日志中注意到这一点。我发帖是为了让遇到同样问题的任何人都能找到答案!