Cocoapods 安装失败,无法构建 gem 本机扩展

Cocoapods installation failed, Failed to build gem native extension

Cocoapods 安装失败,


版本:

macOS 卡特琳娜 10.15.4

ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin19]

自制软件 2.2.6

gem 3.1.2

gem sources -l

*** CURRENT SOURCES ***
https://gems.ruby-china.com

sudo gem install cocoapod

sudo gem install -n /usr/local/bin cocoapods

错误结果:

构建本机扩展。这可能需要一段时间... 错误:安装 cocoapods 时出错: 错误:无法构建 gem 本机扩展。

current directory: /Library/Ruby/Gems/2.6.0/gems/ffi-1.12.2/ext/ffi_c

/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /Library/Ruby/Site/2.6.0 -r ./siteconf20200409-15528-unemw5.rb extconf.rb 检查 ffi.h... * extconf.rb 失败 * 由于某种原因无法创建 Makefile,可能是缺少必要的 图书馆 and/or headers。查看 mkmf.log 文件以获取更多详细信息。你可以 需要配置选项。

提供的配置选项: --with-opt-dir --without-opt-dir --with-opt-include --without-opt-include=${opt-dir}/包括 --with-opt-lib --without-opt-lib=${opt-dir}/lib --with-make-prog --without-make-prog --源目录=。 --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}/包括 --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:585:inblock in try_compile' 来自 /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:534:in with_werror' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:585:intry_compile' 来自 /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1109:in block in have_header' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:959:inblock in checking_for' 来自 /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:361:in block (2 levels) in postpone' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:331:inopen' 来自 /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:361:in block in postpone' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:331:inopen' 来自 /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:357:in postpone' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:958:inchecking_for' 来自 /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1108:in have_header' from extconf.rb:10:insystem_libffi_usable?' 来自 extconf.rb:34:in `'

要了解此扩展编译失败的原因,请查看可在此处找到的 mkmf.log:

/Library/Ruby/Gems/2.6.0/extensions/universal-darwin-19/2.6.0/ffi-1.12.2/mkmf.log

extconf 失败,退出代码 1

Gem 文件将保留安装在 /Library/Ruby/Gems/2.6.0/gems/ffi-1.12.2 中以供检查。 结果记录到 /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-19/2.6.0/ffi-1.12.2/gem_make.out

如果你解决了这个问题?

尝试将 --disable-system-libffi 添加到 gem 安装命令。

这对我有用:

gem inst cocoapods -- --disable-system-libffi

我通过 运行

修复了它
brew install cocoapods

还有 您可能想要删除它:

rm '/usr/local/bin/pod'

要强制 link 并覆盖所有冲突文件:

brew link --overwrite cocoapods

如果尚未安装自制软件,请安装。 https://brew.sh/

这些代码行可以帮助将任何 pods 安装到您在 Macbook M1 上的项目。

sudo arch -x86_64 gem install ffi

arch -x86_64 pod install