sudo gem install cocoapods 错误:无法构建 gem 原生扩展。?
Posted
技术标签:
【中文标题】sudo gem install cocoapods 错误:无法构建 gem 原生扩展。?【英文标题】:sudo gem install cocoapods ERROR: Failed to build gem native extension.? 【发布时间】:2021-01-12 23:16:14 【问题描述】:Mac big sur ,flutter docker -v
[!] Xcode - 为 ios 和 macOS 开发 (Xcode 12.0.1) • Xcode 位于 /Applications/Xcode.app/Contents/Developer • Xcode 12.0.1,内部版本 12A7300 ✗ 未安装 CocoaPods。 CocoaPods 用于检索 iOS 和 macOS 平台端的插件代码,以响应您在 Dart 端的插件使用情况。 如果没有 CocoaPods,插件将无法在 iOS 或 macOS 上运行。 欲了解更多信息,请参阅https://flutter.dev/platform-plugins 安装: sudo gem 安装 cocoapods
$ 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
【问题讨论】:
【参考方案1】:我在 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
【讨论】:
【参考方案2】:https://github.com/ffi/ffi/issues/653#issuecomment-458895497
尝试将 ruby 切换到自制版本。
酿造安装红宝石 酿造链接--覆盖红宝石
如果您需要在 PATH 运行中首先使用 ruby: echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.bash_profile
要让编译器找到 ruby,您可能需要设置: 导出 LDFLAGS="-L/usr/local/opt/ruby/lib" export CPPFLAGS="-I/usr/local/opt/ruby/include"
要让 pkg-config 找到 ruby,您可能需要设置: 导出 PKG_CONFIG_PATH="/usr/local/opt/ruby/lib/pkgconfig"
【讨论】:
【参考方案3】:我在使用Catalina
安装最新的cocoapods
时遇到了类似的问题。我将我的MAC
更新为Big Sur
并更新了Xcode
。应该可以的。
【讨论】:
这个真的不需要。升级 cocoapods 的操作系统? 我对 big sur 也有同样的问题,所以这不是一个好主意...以上是关于sudo gem install cocoapods 错误:无法构建 gem 原生扩展。?的主要内容,如果未能解决你的问题,请参考以下文章
我是不是需要每次都输入:sudo gem install cocoapods
使用 sudo gem install cocoapods 更新 cocopods 后,它仍然显示旧版本