ios - Errors when installing cocoapods with gem
问题描述
I am using macOS Mojave and when I try to install cocoapods using gem I am getting the following error.
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
This error comes when I run the following commands.
sudo gem install cocoapods
sudo gem install -n /usr/local/bin cocoapods
I have already installed xcode command line tools and I get the following message when I run xcode-select --install
xcode-select: error: command line tools are already installed, use "Software Update" to install updates
I have also agreed to xcode license agreements with the command sudo xcodebuild -license
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
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
What do I do to fix this issue ?
解决方案
这个问题的答案可以在这里找到,尽管它与这个问题无关。以下是效果最好的答案片段。
对于macOS 10.14 上的 Xcode 11,即使在安装 Xcode 并安装命令行工具并接受许可后,也可能发生这种情况
sudo xcode-select --install
sudo xcodebuild -license accept
问题是 Xcode 11 附带了 macOS 10.15 SDK,其中包含 ruby2.6 的标头,但不包含 macOS 10.14 的 ruby2.3 的标头。您可以通过运行来验证这是您的问题
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
. 没有必要按照其他答案中的建议通过安装旧的头文件来污染系统目录。相反,通过选择该 SDK,将找到适当的 ruby2.3 标头:
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
推荐阅读
- python - 查看计数器 - 如何显示最近 10 分钟内最热门的文章?
- python-3.x - 如何转置熊猫数据框?
- amazon-web-services - DB 的 API 网关(将所有请求路由到 DB)
- c# - 如何将位图粘贴到另一个位图并在其底部写入文本?
- javascript - React-native with Expo:如何使 Expo auth-session 重定向到同一个应用程序实例而不是单独打开新实例?
- javascript - NodeJS JSON 到客户端处理
- bash - BASH 将列转换为带有标签的行
- python - 优化涉及网格的双循环
- java - MVC 在模型上使用 JTable
- ios - 从 Swift 5 的 NavigationBar 中选择 UIBarButtonItem 时,如何显示带有打开/关闭效果的弹出窗口?