使用gem安装cocoapods时出现错误 [英] Errors when installing cocoapods with gem

查看:1030
本文介绍了使用gem安装cocoapods时出现错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用macOS Mojave,当我尝试使用gem安装cocoapods时,出现以下错误.

I am using macOS Mojave and when I try to install cocoapods using gem I am getting the following error.

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

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.3.0/gems/ffi-1.12.2/ext/ffi_c

/系统/库/框架/Ruby.framework/版本/2.3/usr/bin/ruby -r ./siteconf20200302-707-1iveybq.rb extconf.rb mkmf.rb找不到标头 红宝石的档案 /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/include/ruby.h

/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby -r ./siteconf20200302-707-1iveybq.rb extconf.rb mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/include/ruby.h

extconf失败,退出代码1

extconf failed, exit code 1

宝石文件将继续安装在 /Library/Ruby/Gems/2.3.0/gems/ffi-1.12.2进行检查.结果 登录到 /Library/Ruby/Gems/2.3.0/extensions/universal-darwin-18/2.3.0/ffi-1.12.2/gem_make.out

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

当我运行以下命令时,就会出现此错误.

This error comes when I run the following commands.

sudo gem install cocoapods

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

我已经安装了xcode命令行工具,运行xcode-select --install

I have already installed xcode command line tools and I get the following message when I run xcode-select --install

xcode-select:错误:命令行工具已经安装,使用 软件更新"以安装更新

xcode-select: error: command line tools are already installed, use "Software Update" to install updates

我还同意使用命令sudo xcodebuild -license

/Library/Ruby/Gems/2.3.0/extensions/universal-darwin-18/2.3.0/ffi-1.12.2/gem_make.out中的错误日志显示以下信息

The error log in /Library/Ruby/Gems/2.3.0/extensions/universal-darwin-18/2.3.0/ffi-1.12.2/gem_make.out gives the following

当前目录:/Library/Ruby/Gems/2.3.0/gems/ffi-1.12.2/ext/ffi_c /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby -r ./siteco$ mkmf.rb在以下位置找不到Ruby的头文件 /System/Library/Frameworks/Ruby.fra $

current directory: /Library/Ruby/Gems/2.3.0/gems/ffi-1.12.2/ext/ffi_c /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby -r ./siteco$ mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.fra$

extconf失败,退出代码1

extconf failed, exit code 1

我该如何解决此问题?

推荐答案

在此处找到答案

The answer for this can be found here here although it is unrelated to this question. Below is a snippet of the answer which works best.

对于 macOS 10.14上的Xcode 11 ,即使在安装Xcode和安装命令行工具并接受许可后,也会发生这种情况

For Xcode 11 on macOS 10.14, this can happen even after installing Xcode and installing command-line tools and accepting the license with

sudo xcode-select --install
sudo xcodebuild -license accept

问题是Xcode 11附带了macOS 10.15 SDK,其中包含ruby2.6的标头,但不包含macOS 10.14的ruby2.3的标头.您可以通过运行

The issue is that Xcode 11 ships the macOS 10.15 SDK which includes headers for ruby2.6, but not for macOS 10.14's ruby2.3. You can verify that this is your problem by running

ruby -rrbconfig -e 'puts RbConfig::CONFIG["rubyhdrdir"]'

在带有Xcode 11的macOS 10.14上打印不存在路径

which on macOS 10.14 with Xcode 11 prints the non-existent path

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0

但是,Xcode 11在/Library/Developer/CommandLineTools/SDKs/MacOS10.14.sdk中安装了macOS 10.14 SDK.不必按照其他答案中的建议安装旧的头文件来污染系统目录.相反,通过选择该SDK,将找到适当的ruby2.3标头:

However, Xcode 11 installs a macOS 10.14 SDK within /Library/Developer/CommandLineTools/SDKs/MacOS10.14.sdk. It isn't necessary to pollute the system directories by installing the old header files as suggested in other answers. Instead, by selecting that SDK, the appropriate ruby2.3 headers will be found:

sudo xcode-select --switch /Library/Developer/CommandLineTools
ruby -rrbconfig -e 'puts RbConfig::CONFIG["rubyhdrdir"]'

现在应该可以正确打印

/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0

同样,选择该SDK时gem install应该可以工作.

Likewise, gem install should work while that SDK is selected.

要切换回使用当前的Xcode 11 SDK,请使用

To switch back to using the current Xcode 11 SDK, use

sudo xcode-select --switch /Applications/Xcode.app

这篇关于使用gem安装cocoapods时出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆