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

128
当我在 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"

我已经安装了Xcode 10.1。

xcode-select -p
/Applications/Xcode.app/Contents/Developer
26个回答

2

对我来说,"rvm install ruby"(不使用brew)有效,然后按照这里的步骤进行操作:

$ sudo rm -rf /Library/Developer/CommandLineTools
$ xcode-select --install

然后

export PKG_CONFIG_PATH="/usr/local/opt/ruby/lib/pkgconfig" 

在所有这些之后,它成功了。

2

MacOS Ventura 13.6

在尝试使用以下脚本引导React Native项目时遇到了一些麻烦:npx react-native@latest init <项目名称>,这是根据官方文档操作的。尽管在更新到Ventura 13.6后进行了Xcode和命令行工具的全新安装,但仍然遇到了以下错误:fatal error: 'ruby/config.h'文件未找到

解决方案:

  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
    
  2. 复制缺失的头文件:

    sudo cp ../../../../Headers/ruby/config.h .
    
  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/
    
  4. 安装 "activesupport" gem:

    sudo gem install activesupport -v 6.1.7.6
    
  5. 手动安装 cocoapods:

    sudo gem install cocoapods
    
现在它终于按照预期工作了。看起来有个同行开发者在某个时候做错了什么。
希望这对你有帮助!

1

我在上面没有找到这个提到的内容,也不确定这是否是通用解决方案。提到这一点是因为这可能仍然有用。

至少在Xcode 14/macOS 13/12中,可以使用原始Ruby,而不会弄乱符号链接,前提是在主机上安装了macOS命令行工具包。问题在于命令行工具包捆绑了最新版本macOS的SDK,尤其是与主机匹配的版本(据我所见,该SDK具有包含ruby/config.h的目录的“正确”名称)。然后只需要在环境中覆盖SDKROOT(这是最关键的事情),将所有低级工具如clang指向与“正确”版本的SDK匹配的自定义根目录即可。(如果没有覆盖,则仍将使用与工具捆绑的默认SDK,可能与运行在主机上的macOS版本匹配或不匹配)。

macos_major_vers=$(sw_vers -productVersion | sed 's/^\([^.]*\)\..*$/\1/') # e.g. 12
export SDKROOT=/Library/Developer/CommandLineTools/SDKs/MacOSX"$macos_major_vers".sdk

# ... build commands for Ruby gems go here.

1

MacOS Big Sur Beta 8

尝试以下操作:

  1. 安装 rbenv
  • git clone https://github.com/rbenv/rbenv.git ~/.rbenv

  • cd ~/.rbenv && src/configure && make -C src

  • 将 ~/.rbenv/bin 添加到 $PATH 中,以便访问 rbenv 命令行实用程序。 请参见:https://github.com/rbenv/rbenv#basic-github-checkout

  • 确保已将 export PATH="$HOME/.rbenv/shims:${PATH}" 添加到您的 $PATH

  1. xcode-select --switch /Applications/Xcode.app/Contents/Develope

  2. gem install cocoapods 应该能够正常工作!


1
这并没有解决我的问题,但是2018年11月20日的那个解决方案解决了。 - yukashima huksay

1
在macOS Monteray 12.6.5上,我通过遵循修改后的路径版本到macOS Mojave 'ruby/config.h' file not found评论来解决了这个cocoapod Unity错误。
cd /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.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 and a sudo ln -sf universal-darwin22 universal-darwin21

然后CocoaPods安装成功了。 干杯


1
谢谢!这对我在Monteray上起作用了。我只需要将路径中的MacOSX12.1.sdk替换为MacOSX13.1.sdk。 - undefined

1
我遇到了类似的问题。在我的情况下,出现了错误。
In file included from /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.h:33:
/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/ruby.h:24:10: fatal error: 'ruby/config.h' file not found
#include "ruby/config.h"
     ^~~~~~~~~~~~~~~

我注意到的是,我使用的是MacOS 13.5版本,而上面的错误信息显示的是MacOS 14。我的Xcode版本是15。
我升级到了MacOS Sonoma,即版本14,问题得到了解决。
问题似乎是由于某个版本不匹配引起的。

0

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

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

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


当我尝试为macvim安装Command-T时,遇到了问题,担心需要重新安装Mojave。相反,我发现系统ruby实际上是Ruby 2.3.7(Macvim是针对此系统ruby版本2.3.7构建的),并使用rbenv安装了ruby 2.3.7。一旦安装并将其设置为我的默认ruby,我就可以像平常一样安装Command-T。可能仍然需要考虑在以后重新安装Mojave,但通过rbenv安装Ruby 2.3.7帮助我在不进行此操作的情况下使事情正常运行。我希望这能帮助其他人解决类似的问题。 - Kyle Tolle
ReDetection解决方案起作用了,我还使用了System Ruby。我的意思是这就是下载的目的吧?适用于Mac OS X的头文件。 - Logemann
在我的情况下,/Library/Developer/CommandLineTools中不包含Packages文件夹。正如我上面所写的那样,重新安装Mojave是一个解决方案(您可以在不丢失数据的情况下重新安装它)。 - maksimr

0

如果您在执行bundle install时遇到此错误,请参见以下内容 -

我尝试了所有已发布的解决方案,但都无法解决问题。对我有效的方法是从日志中安装指定的bundler版本。例如,我的控制台警告我关于不匹配的bundler版本,然后我运行gem install bundler:2.2.32来解决它,这样就为我修复了bundle install命令。在我的情况下,我使用的是rvm和ruby版本3.0.0。


0

我在卸载旧版Xcode后遇到了这个问题。通常,我会将其安装在 /Applications/Xcode-13.2.1.app 中。但是,xcode-select -p 仍然显示它指向的是旧版本。

我只需运行 sudo xcode-select -s /Applications/Xcode-13.2.1.app,一切就可以恢复正常了。


0

我在安装eventmachine 1.2.7时遇到了类似的问题,以下方法适用于我(macOS 10.15.5):

(我使用fish

  1. brew install ruby
  2. 将以下内容添加到~/.config/fish/config.fish中(不包括fish,只需将这些添加到路径中)
    1. fish_add_path /usr/local/opt/ruby/bin
    2. fish_add_path /usr/local/lib/ruby/gems/3.0.0/bin
  3. set -gx CPPFLAGS "-I/usr/local/opt/ruby/include"
  4. set -gx LDFLAGS "-L/usr/local/opt/ruby/lib"
  5. set -gx PKG_CONFIG_PATH "/usr/local/opt/ruby/lib/pkgconfig"
  6. sudo gem install eventmachine -v '1.2.7' --source 'https://rubygems.org/'

我是在通过brew安装ruby之后得到了set -gx命令。

我尝试重新安装Xcode工具(12.3版本,因为我暂时无法升级到Big Sur),并重新接受协议,但这并没有改变任何东西。


需要注意的是,这是安装 eventmachine 1.2.7 后出现的。我得到的日志错误将此路径作为其标记之一:

-I/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 -I

请注意,它试图查找.../MacOSX11.1.sdk/...,但我有10.15.5。即使手动设置CPPFLAGS、LDFLAGS、PKG_CONFIG_PATH也无法工作,因为我使用的是系统ruby或者rbenv提供的ruby版本,但我太沮丧了,不想深入挖掘这个问题。所以,我重新安装了brew的ruby!

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接