提问者:小点点

sudo gem install cocoapods 错误:无法构建 gem 本机扩展。?


Mac big sur,flutter docker -v

[!]Xcode-为iOS和macOS开发(Xcode 12.0.1)•Xcode at/Applications/Xcode.app/Contents/Developer•Xcode 12.0.2,内部版本12A7300✗ 未安装CocoaPods。CocoaPods用于检索iOS和macOS平台端的插件代码,以响应Dart端的插件使用。没有CocoaPods,插件将无法在iOS或macOS上运行。有关详细信息,请参阅https://flutter.dev/platform-plugins要安装:sudo gem install cocapods

$ sudo gem install cocoapods
Building native extensions. This could take a while...
ERROR:  Error installing cocoapods:
    ERROR: Failed to build gem native extension.

    current directory: /Library/Ruby/Gems/2.6.0/gems/ffi-1.13.1/ext/ffi_c
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0 -r ./siteconf20200927-68237-n9jbyc.rb extconf.rb
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/$(RUBY_BASE_NAME)
    --with-ffi_c-dir
    --without-ffi_c-dir
    --with-ffi_c-include
    --without-ffi_c-include=${ffi_c-dir}/include
    --with-ffi_c-lib
    --without-ffi_c-lib=${ffi_c-dir}/lib
    --enable-system-libffi
    --disable-system-libffi
    --with-libffi-config
    --without-libffi-config
    --with-pkg-config
    --without-pkg-config
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:467:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:546:in `block in try_link0'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/tmpdir.rb:93:in `mktmpdir'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:543:in `try_link0'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:570:in `try_link'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:672:in `try_ldflags'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1832:in `pkg_config'
    from extconf.rb:9:in `system_libffi_usable?'
    from extconf.rb:42:in `<main>'

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

  /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-20/2.6.0/ffi-1.13.1/mkmf.log

extconf failed, exit code 1

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

共3个答案

匿名用户

我在Catalina也遇到了同样的问题。我通过安装最新版本的ruby(2.7.2)解决了这个问题。

首先安装Ruby版本管理器rvm:

curl -L https://get.rvm.io | bash -s stable

然后安装最新版本的ruby:

rvm install ruby-2.7.2

最后再试一次安装cocoapods:

sudo gem install cocoapods

匿名用户

https://github.com/ffi/ffi/issues/653#issuecomment-458895497

尝试将ruby切换到自制版本。

brew install ruby brew link --overwrite ruby

如果您需要在PATH中首先使用ruby,请运行:echo'export PATH=“/usr/local/opt/ruby/bin:$PATH”'

为了让编译器找到 ruby,您可能需要设置:export LDFLAGS=“-L/usr/local/opt/ruby/lib” export CPPFLAGS=“-I/usr/local/opt/ruby/include”

对于pkg配置来查找ruby,您可能需要设置:export pkg_config_PATH=“/usr/local/opt/ruby/lib/pkgconfig”

匿名用户

我在与卡塔琳娜安装最新的椰子足时遇到了类似的问题。我将我的MAC更新为Big Sur,并更新了Xcode。这应该行得通。