找不到macOS Mojave'ruby/config.h'文件

mak*_*imr 5 ruby vim macos-mojave

当我尝试在macOS Mojave(10.14.1)上使用ruby支持( - enable-rubyinterp)构建vim(8.1.0509)时出现错误:

In file included from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0/ruby.h:33:
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0/ruby/ruby.h:24:10: fatal error:
      'ruby/config.h' file not found
#include "ruby/config.h"
Run Code Online (Sandbox Code Playgroud)

我已经安装了Xcode 10.1.

xcode-select -p
/Applications/Xcode.app/Contents/Developer
Run Code Online (Sandbox Code Playgroud)

谢谢

PS在我的问题上看到我的答案它解释了为什么我的问题与Xcode的问题不同

Jon*_*hoi 88

Catalina、Big Sur 等(截至 2020 年和 2021 年)

最新版本的 macOS 和 Xcode(例如 Catalina 10.15 和 Xcode 12.2)肯定会出现这种情况。重新安装 Xcode 并xcode-select --install没有帮助我(已经发布的解决方案似乎已经过时)。我不想使用,rvm因为它可能会导致一些烦人的问题。

我通过手动创建符号链接做了一个解决方法:

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

在哪里ruby/config.h可以找到: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/Headers/ruby/config.h

您应该根据您当前的 xcode 安装更改 SDK 版本(例如上例中的 11.1)。

也很可能遇到另一个.../universal-darwin19/ruby/config.h找不到的错误(无法安装 Commonmarker gemjekyll 需要)macos)。它可以通过以下方式快速修复:

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)

  • 我在 Xcode 13 beta 中遇到了非常类似的问题(不是使用 vim,而是使用不同的项目)。看起来这些文件现在位于 Xcode 13 的“universal-darwin21”文件夹中,因此我必须将命令更新为“ln -sf universal-darwin21 universal-darwin19”,并添加“ln -sf universal-darwin21 universal-” darwin20` 来构建我的项目。 (12认同)
  • 这是一个很好的技术,但需要更新和简化:`cd $(xcode-select -p)/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/Current/ usr/include/ruby-2.*`,然后查看您拥有的`universal-darwin*/`目录(目录?),然后根据需要使用较低版本号`20`或`21`创建一个符号链接,例如“sudo ln -s universal-darwin21 universal-darwin20”。 (6认同)
  • 为我工作!非常感谢。在我的 BigSur 上,我运行了 `cd /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/ include/ruby-2.6.0/ruby/` 然后是 'sudo ln -sf ../../../../Headers/ruby/config.h` 然后是 cd /Applications/Xcode.app/Contents/ Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0` 和 `sudo ln -sf universal -darwin21 通用-darwin20` (5认同)
  • 最后的命令应该是 ln -sf universal-darwin[x] universal-darwin[x-1] ,其中 x 是 .../include/ruby-2.6.0 路径中存在的版本。对我来说,它是“ln -sf universal-darwin22 universal-darwin21” (4认同)
  • 尝试安装“rbenv”。尝试卸载并重新安装“xcode 工具”。但只有这个解决方案有效。尽管如此,我正在认真考虑备份所有内容并在这一切之后重置我的机器 (2认同)

Ede*_*den 39

在 macOS Catalina 上
多次安装和卸载开发人员工具后,这是唯一对我有用的方法:

首先安装 Ruby 版本管理器 rvm:

curl -L https://get.rvm.io | bash -s stable
Run Code Online (Sandbox Code Playgroud)

然后安装最新版本的ruby:

rvm install ruby-2.7.2
Run Code Online (Sandbox Code Playgroud)

最后再次尝试安装 cocoapods:

sudo gem install cocoapods
Run Code Online (Sandbox Code Playgroud)

(来自这个答案:https : //stackoverflow.com/a/65033418/3605761

编辑:可能需要rvm reinstall ruby-2.7.2而不是rvm install ruby-2.7.2在第 2 步。

  • 确保安装后使用正确版本的 ruby​​:`ruby --version` 检查版本并使用 `rvm use 2.7.2` 进行设置 (2认同)
  • 对于 Monterey xCode 14.2 运行: ```rvm install ruby​​-3.0.6 --with-openssl-dir=$(brew --prefix openssl@1.1)``` (2认同)

ReD*_*ion 31

这个答案对我有帮助:https://stackoverflow.com/a/53194299/2105993

brew install rbenv ruby-build
echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile 
rbenv install 2.6.3
rbenv global 2.6.3
Run Code Online (Sandbox Code Playgroud)

  • 这应该是公认的答案@maksimr,因为它可以在不完全重新安装 macOS 的情况下解决问题 (3认同)
  • 对我来说`brew install ruby​​`,然后`export PKG_CONFIG_PATH="/usr/local/opt/ruby/lib/pkgconfig"`解决了这个问题(这是`sudo gem install eventmachine -v '1.2.7'`) (2认同)

小智 15

如果您在 Mac Big Sur 中遇到此问题,重新安装CommandLineTools可以解决此问题。

sudo rm -rf /Library/Developer/CommandLineTools

xcode-select --install
Run Code Online (Sandbox Code Playgroud)


lea*_*vez 13

这是因为在编译 gem 的本机扩展时,某些版本的 Xcode 没有适用于其运行的操作系统的 macOS SDK。

确保 Xcode 版本和 macOS 版本相互匹配:

  • macOS 10.15:Xcode < 12.2
  • macOS 11:Xcode >= 12.2,<= 13.0
  • macOS 12:Xcode >= 13.1,<= 14.0
  • macOS 13:Xcode >= 14.1,< 15.0
  • macOS 14:Xcode >= 15.0

PS 我在 MacPorts 的文档中找到了类似的列表,它可能是最新的。(在https://www.macports.org/install.php13.1 or later for Monterey中搜索)

  • 这似乎也是 macOS Ventura 的问题;它需要 Xcode 14.1。 (3认同)

ata*_*man 12

我有同样的问题。无法安装具有本机扩展名的gem。跑步

$ open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
Run Code Online (Sandbox Code Playgroud)

失败,因为文件不存在。看起来Mojave可以破坏命令行工具。

我通过删除Xcode命令行工具,再次安装它们,然后安装缺少的标头来解决此问题:

$ sudo rm -rf /Library/Developer/CommandLineTools
$ xcode-select --install
$ open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
Run Code Online (Sandbox Code Playgroud)


小智 5

在 macOS Catalina 上 如果安装了多个版本的 xcode,xcode12/xcode12.4 等。请尝试在 xcode 首选项中更改您的 xcode 命令行工具。它可能有效!


Tho*_*ann 5

MacOS 文图拉 13.6

在尝试使用以下脚本引导 React Native 项目时经历了这种无意义的事情: npx react-native@latest init <Project Name>按照官方文档。遇到以下错误:fatal error: 'ruby/config.h' file not found尽管在更新到 Ventura 13.6 后全新安装了 xcode 和命令行工具。

解决方案:

  1. 导航到有问题的文件夹:

    cd /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby
    
    Run Code Online (Sandbox Code Playgroud)
  2. 复制缺少的头文件:

    sudo cp ../../../../Headers/ruby/config.h .
    
    Run Code Online (Sandbox Code Playgroud)
  3. 将“universal-darwin23”文件夹重命名为“universal-darwin22”:

    sudo mv /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin23/ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin22/
    
    Run Code Online (Sandbox Code Playgroud)
  4. 安装“activesupport”gem:

    sudo gem install activesupport -v 6.1.7.6
    
    Run Code Online (Sandbox Code Playgroud)
  5. 手动安装cocoapods:

    sudo gem install cocoapods
    
    Run Code Online (Sandbox Code Playgroud)

现在它终于按预期工作了。看起来某些开发人员同事在某个时候做了错事。

希望这可以帮助!


mak*_*imr 0

我的问题不同于 - Yosemite升级破坏了 ruby​​.h

正如您在问题描述中看到的,它是System的 ruby​​,而不是 Xcode 的 ruby​​,因此重新安装 Xcode 或符号链接在这里没有帮助。

答: 我已重新安装 macOS Mojave,没有丢失任何数据,这解决了问题。