问题描述
我正在学习编程,并且尝试安装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 ./siteconf20201006-615-fryp4a.rb extconf.rb
checking for ffi.h... *** 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:585:in `block in try_compile'
from /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:in `try_compile'
from /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:in `block in checking_for'
from /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:in `open'
from /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:in `open'
from /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:in `checking_for'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1108:in `have_header'
from extconf.rb:10: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
我知道有一行写着“您必须首先安装开发工具”,一开始确实是这样。然后,我安装了Xcode命令行工具(由于xcode-select --install
行不起作用,我不得不从Apple Developer手动下载它),然后尝试再次安装cocoapods。但是即使重新启动后,我也遇到同样的错误。
它也有日志的路由,这就是它的意思:
package configuration for libffi is not found
"xcrun clang -o conftest -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin20 -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby/backward -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -g -Os -pipe -DHAVE_GCC_ATOMIC_BUILTINS -DUSE_FFI_CLOSURE_ALLOC conftest.c -L. -L/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib -L. -L/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.0.Internal.sdk/usr/local/lib -lruby.2.6 "
In file included from conftest.c:1:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby.h:33:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby/ruby.h:24:10: Fatal error: 'ruby/config.h' file not found
#include "ruby/config.h"
^~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby/ruby.h:24:10: note: did not find header 'config.h' in framework 'ruby' (loaded from '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks')
1 error generated.
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main(int argc,char **argv)
4: {
5: return 0;
6: }
/* end */
所以,我被困住了。 我目前正在使用macOS Big Sur Beta 9和Xcode 12.0.1(非Beta版)。
解决方法
XCode 的 ruby 框架似乎有问题。使用最新版本干净地重新安装 Xcode.app,运行 xcode-select --install
或 --select
对我不起作用。
这是我设法让它与 XCode 12.2 和 Catalina (10.15.7) 一起运行的方法:https://stackoverflow.com/a/65481787/1534182
TL;DR)
cd /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby
ln -sf ../../../../Headers/ruby/config.h
cd /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0
ln -sf universal-darwin20 universal-darwin19
(编辑符号链接中的固定错字)
,通过在macOS Big Sur上将Xcode升级到12.2来解决。
然后运行:
sudo gem install -n /usr/local/bin cocoapods
浪费了5个小时,因为我认为这是宝石的问题。
,好,今天我终于能够成功安装Cocoapods,但这是一个奇怪的过程。
学习时,人们通常会告诉您不要使用beta,而当我在Xcode的AppStore稳定版本中时,我正在运行Big Sur B9;那可能就是问题所在。 我完全卸载了Xcode 12.0.1,然后从Apple Developer Xcode 12.2 beta下载了。然后,我也下载并安装了12.2 beta版的命令行工具,并再次在终端机中运行了cocoapods安装……瞧!
在安装并运行Xcode beta之后,我可以安装并正常运行了。 也许当BigSur上市时,这将得到解决吗?因为不是每个人都需要或必须运行Xcode beta版本。
,我遇到了完全相同的问题
$ sudo gem install cocoapods
...
checking for ffi.h... *** extconf.rb failed ***
Could not create Makefile due to some reason,probably lack of necessary
libraries and/or headers.
...
通过将ruby版本升级到2.7.2修复。 https://stackoverflow.com/a/65033418/4982169
的积分我使用rbenv管理红宝石版本。
,或者如果你已经安装了可可豆荚就运行
brew 安装 cocoapods
显示一些警告信息后
Warning: cocoapods 1.10.1 is already installed,it's just not linked.
要链接此版本,请运行: brew link cocoapods 或
brew link --overwrite cocoapods
这对我真的很有帮助。谢谢
,这对我有用:
https://github.com/CocoaPods/CocoaPods/issues/10286#issuecomment-747512270
引用:
- 从 Apple Developer Downloads 下载命令行工具 11.5
- sudo rm -rf /Library/Developer/CommandLineTools
- 从 .dmg/.pkg 安装命令行工具
- sudo xcode-select --switch /Library/Developer/CommandLineTools
- [sudo] gem install [--user-install] cocoapods
- sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
高于溶胶。可能适用于每个人,也可能不适用于每个人,但请确保交叉检查命令行工具。它必须设置而不是空白。
,将默认的 Xcode 命令行工具从 12.4 版切换到 11.7 版为我解决了这个问题。
我在 Catalina (10.15.7) 上安装了两个 Xcode 版本,所以我使用 Xcode 首选项(位置/命令行工具:) 进行了切换,在弹出菜单中选择“Xcode 11.7”。然后我退出 Xcode 并再次运行安装命令:
sudo gem install cocoapods
在我遇到相同的“缺少标题”错误之前,现在安装顺利进行。
命令行工具可以单独安装,无需自己安装Xcode。然后您将使用终端来切换版本。当前默认工具的路径由
返回xcode-select -p
和切换版本是使用
完成的sudo xcode-select -s {path-to-tools}
安装 CocoaPods 后,我切换回最新的命令行工具,并在我当前的一个项目上进行了“pod install”,成功而没有发生任何事故。所以早期的版本似乎只需要安装 CocoaPods,而不是它的操作。