MacOS 10.13 gem install ffi (or fpm)失败

由于fpm安装依赖ffi

$ sudo gem install --no-ri --no-rdoc fpm
Building native extensions.  This could take a while...
ERROR:  Error installing fpm:
        ERROR: Failed to build gem native extension.

    current directory: /Library/Ruby/Gems/2.3.0/gems/ffi-1.11.1/ext/ffi_c
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby -r ./siteconf20190610-24900-1wf5ec3.rb extconf.rb
checking for ffi.h... no
checking for ffi.h in /usr/local/include,/usr/include/ffi... yes
checking for ffi_call() in -lffi... yes
checking for ffi_closure_alloc()... 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

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /Library/Ruby/Gems/2.3.0/extensions/universal-darwin-17/2.3.0/ffi-1.11.1/mkmf.log
...
...
ld: warning: The i386 architecture is deprecated for macOS (remove from the Xcode build setting: ARCHS)
Undefined symbols for architecture i386:
  "___x86.get_pc_thunk.bx", referenced from:
      _ffi_call_i386 in sysv.o
      _ffi_closure_raw_SYSV in sysv.o
      _ffi_closure_raw_THISCALL in sysv.o
  "___x86.get_pc_thunk.dx", referenced from:
      _ffi_closure_i386 in sysv.o
      _ffi_closure_STDCALL in sysv.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [libffi.la] Error 1
make[2]: *** [all-recursive] Error 1
make[1]: *** [all] Error 2
make: *** ["/Library/Ruby/Gems/2.3.0/gems/ffi-1.11.1/ext/ffi_c"/libffi-i386/.libs/libffi_convenience.a] Error 2

make failed, exit code 2

Gem files will remain installed in /Library/Ruby/Gems/2.3.0/gems/ffi-1.11.1 for inspection.
Results logged to /Library/Ruby/Gems/2.3.0/extensions/universal-darwin-17/2.3.0/ffi-1.11.1/gem_make.out

根据上边报错信息可以得知是由于安装ffi失败导致,所以我们尝试安装ffi
首先Google了这句报错,ld: warning: The i386 architecture is deprecated for macOS (remove from the Xcode build setting: ARCHS),得到的信息是Apple has removed to ability to compile 32 bit programs on macos with xcode10,难道我们只能降级xcode了?这不是又会带来其他的问题?所以我们再次去Google别的报错信息。

Google gem install ffi macos 10.13 得到ffi (1.9.21) instalation fails in linux 该评论在MacOS下解决了问题:

$ brew install automake autoconf libtool
$ gem install ffi -v '1.9.21'

于是执行了brew install,安装了确实的组件,尝试gem install ffi,仍然报了和之前一样的错误。

换个思路想一下,是不是我们ffi版本太高了?于是试了一下gem install ffi -v '1.9.21'指定gem版本。这次终于安装成功了。

$ sudo gem install ffi -v '1.9.21'
Fetching: ffi-1.9.21.gem (100%)
Building native extensions.  This could take a while...
Successfully installed ffi-1.9.21
Parsing documentation for ffi-1.9.21
Installing ri documentation for ffi-1.9.21
Done installing documentation for ffi after 4 seconds

接下来安装fpm:

$ sudo gem install --no-ri --no-rdoc fpm
Fetching: ruby-xz-0.2.3.gem (100%)
Successfully installed ruby-xz-0.2.3
Fetching: childprocess-0.9.0.gem (100%)
Successfully installed childprocess-0.9.0
Fetching: arr-pm-0.0.10.gem (100%)
Successfully installed arr-pm-0.0.10
Fetching: backports-3.15.0.gem (100%)
Successfully installed backports-3.15.0
Fetching: fpm-1.11.0.gem (100%)
Successfully installed fpm-1.11.0
5 gems installed

搞定

你可能感兴趣的:(mac)