ios - 使用 gem 安装 cocoapods 时出错

标签 ios xcode macos rubygems

我正在使用 macOS Mojave,当我尝试使用 gem 安装 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.3.0/gems/ffi-1.12.2/ext/ffi_c

/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 failed, exit code 1

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



当我运行以下命令时会出现此错误。
sudo gem install cocoapods

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

我已经安装了 xcode 命令行工具,当我运行 xcode-select --install 时收到以下消息

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



我还同意使用命令 sudo xcodebuild -license 的 xcode 许可协议(protocol)
/Library/Ruby/Gems/2.3.0/extensions/universal-darwin-18/2.3.0/ffi-1.12.2/gem_make.out 中的错误日志给出以下

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 failed, exit code 1



我该怎么做才能解决这个问题?

最佳答案

可以在这里找到答案 here虽然它与这个问题无关。以下是效果最好的答案片段。

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

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

问题是 Xcode 11 附带了 macOS 10.15 SDK,其中包含 ruby​​2.6 的 header ,但不包含 macOS 10.14 的 ruby​​2.3 的 header 。您可以通过运行来验证这是您的问题

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

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

/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,将找到适当的 ruby​​2.3 header :

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

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

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

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

关于ios - 使用 gem 安装 cocoapods 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60481623/

相关文章:

ios - linkedin 应用程序的自定义 URL 链接

c++ - OpenGL:从 Visual Studio 源代码到 XCode 4?

ios - 如何将 View 高度设置为等于其宽度

macos - NSOutlineView 编译错误 : Semantic Issue 'moveRowAtIndex:toIndex:' is unavailable

ios - 无法将从相机拍摄的图像传递到另一个 View Controller

ios - 正在主线程上执行长时间运行的操作

ios - applicationDidBecomeActive 方法阻塞了我的 UI

ios - Mapbox iOS SDK 3 - 点击注释时不显示注释标题

objective-c - 从 `username` 给出的 `SecKeychainItemRef` 中提取 `SecKeychainFindGenericPassword` ?

macos - 如何在 Mac OS X 上构建 DTrace?