xcode 使用 gem 安装 cocoapods 时出错
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/60481623/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Errors when installing cocoapods with gem
提问by Muljayan
I am using macOS Mojave and when I try to install cocoapods using gem I am getting the following error.
我正在使用 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
构建本机扩展。这可能需要一段时间... 错误:安装 cocoapods 时出错:错误:无法构建 gem 本机扩展。
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 在 /System/Library 找不到 ruby 的头文件/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/include/ruby.h
extconf 失败,退出代码 1
Gem 文件将保留安装在 /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
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 命令行工具,运行时收到以下消息 xcode-select --install
xcode-select: error: command line tools are already installed, use "Software Update" to install updates
xcode-select: 错误:命令行工具已经安装,使用“软件更新”安装更新
I have also agreed to xcode license agreements with the command sudo xcodebuild -license
我也同意 xcode 许可协议与命令 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
错误登录/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
当前目录:/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 在 /System/Library/Frameworks/Ruby.fra$ 找不到 ruby 的头文件
extconf 失败,退出代码 1
What do I do to fix this issue ?
我该怎么做才能解决这个问题?
回答by Anshul Kataria
The answer for this can be found here herealthough it is unrelated to this question. Below is a snippet of the answer which works best.
尽管它与此问题无关,但可以在此处找到答案。以下是最有效的答案片段。
For Xcode 11 on macOS 10.14, this can happen even after installing Xcode and installing command-line tools and accepting the license with
对于macOS 10.14 上的 Xcode 11,即使在安装 Xcode 并安装命令行工具并接受许可证后,也会发生这种情况
sudo xcode-select --install
sudo xcodebuild -license accept
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
问题在于 Xcode 11 提供了 macOS 10.15 SDK,其中包含 ruby2.6 的头文件,但不包含 macOS 10.14 的 ruby2.3 头文件。您可以通过运行来验证这是您的问题
ruby -rrbconfig -e 'puts RbConfig::CONFIG["rubyhdrdir"]'
which on macOS 10.14 with Xcode 11 prints the non-existentpath
在 macOS 10.14 和 Xcode 11 上打印不存在的路径
/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
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:
但是,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"]'
This should now correctly print
这现在应该正确打印
/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0
Likewise, gem install
should work while that SDK is selected.
同样,gem install
应在选择该 SDK 时工作。
To switch back to using the current Xcode 11 SDK, use
要切换回使用当前的 Xcode 11 SDK,请使用
sudo xcode-select --switch /Applications/Xcode.app
回答by Hi?n Nguy?n
sudo xcode-select --switch /Library/Developer/CommandLineTools
须藤 xcode-select --switch /Library/Developer/CommandLineTools
ruby -rrbconfig -e 'puts RbConfig::CONFIG["rubyhdrdir"]'
ruby -rrbconfig -e 'puts RbConfig::CONFIG["rubyhdrdir"]'
回答by Nico Pan
- Excute:
ruby -rrbconfig -e 'puts RbConfig::CONFIG["rubyhdrdir"]'
to figure out your ruby configuration. - If the output is a nonexistent MacOSX10.15 path. Like:
/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
You should correct the configuration by doing next step. - Excute:
sudo xcode-select --switch /Library/Developer/CommandLineTools
- You can excute:
ruby -rrbconfig -e 'puts RbConfig::CONFIG["rubyhdrdir"]'
again to see if the path has changed. - The output is
/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0
- Excute:
ruby -rrbconfig -e 'puts RbConfig::CONFIG["rubyhdrdir"]'
找出你的 ruby 配置。 - 如果输出是不存在的 MacOSX10.15 路径。像:
/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
您应该通过执行下一步来更正配置。 - 执行:
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
Then you can excute gem install
to install cocoapods !
然后就可以执行gem install
安装cocoapods了!