安装 CocoaPods 时出错 - macOS BigSur

Max*_*hez 9 macos xcode rubygems libffi cocoapods

我正在学习如何编程,我正在尝试安装 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
Run Code Online (Sandbox Code Playgroud)

我知道有一行写着“你必须先安装开发工具”,一开始确实是这样。然后我安装了 Xcode 命令行工具(我不得不从 Apple Developer 手动下载它,因为该xcode-select --install行不起作用),并尝试再次安装 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 */
Run Code Online (Sandbox Code Playgroud)

所以,我被困住了。我目前使用的是 macOS Big Sur Beta 9 和 Xcode 12.0.1(非测试版)。

Mik*_*laj 11

我有同样的问题(Catalina 10.15.7 & Xcode 12.3)。

我使用自制软件而不是 gem:

brew install cocoapods
Run Code Online (Sandbox Code Playgroud)

  • 适用于“macOS BigSur 11.6.2 MacBook Pro(M1,2020)Xcode 13.2.1” (2认同)

Har*_*nan 7

或者如果您已经安装了可可豆荚,只需运行

酿造安装cocoapods

在显示一些警告消息后

Warning: cocoapods 1.10.1 is already installed, it's just not linked.
Run Code Online (Sandbox Code Playgroud)

要链接此版本,请运行:brew link cocoapods 或

酿造链接——覆盖cocoapods

这对我来说真的很有帮助。谢谢


小智 6

通过在 macOS Big Sur 上将 Xcode 升级到 12.2 来解决。

然后运行:

sudo gem install -n /usr/local/bin cocoapods
Run Code Online (Sandbox Code Playgroud)

浪费了 5 个小时,因为我认为这是宝石的问题。

成功安装 cocoapods

  • 这对我不起作用。 (2认同)

Jon*_*hoi 6

XCode 的 ruby​​ 框架似乎有问题。使用最新版本干净地重新安装 Xcode.app 并运行xcode-select --install--select对我不起作用。

这就是我设法让它与 XCode 12.2 和 Catalina (10.15.7) 一起运行的方法:https ://stackoverflow.com/a/65481787/1534182

特尔;博士)

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
Run Code Online (Sandbox Code Playgroud)

(编辑符号链接中的固定错字)


Max*_*hez 2

好吧,今天我终于成功安装了 Cocoapods,但这是一个奇怪的过程。

\n

当学习时,人们通常会告诉你远离 beta 版本,而当我使用稳定的 AppStore 版本的 Xcode 时,我正在运行 Big Sur B9;这可能就是问题所在。\n我完全卸载了 Xcode 12.0.1,然后从 Apple Developer Xcode 12.2 beta 下载。然后我下载并安装了 12.2 beta 的命令行工具,并再次在 Terminal\xe2\x80\xa6 中运行 cocoapods 安装,瞧!

\n

安装并运行 Xcode beta 后,我能够安装并且现在工作正常。\n也许当 BigSur 公开时这个问题就会得到解决?因为并不是每个人都需要或必须运行 Xcode beta 版本。

\n

  • 我使用的是 Xcode 12.2,但在 macOS Catalina 上仍然遇到同样的问题。 (2认同)