“Yosemite 升级破坏了 ruby.h”

23
自从升级到Yosemite以后,我尝试构建任何包含ruby.h的东西时都会出现这个错误:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/ruby.h:33:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/ruby/ruby.h:24:10: fatal error: 'ruby/config.h' file not found
#include "ruby/config.h"
         ^
1 error generated.
make[1]: *** [objects/if_ruby.o] Error 1
make[1]: *** Waiting for unfinished jobs....
make: *** [first] Error 2

果然,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/ruby/config.h确实不存在。

$ ls -laF /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/ruby/
total 72
drwxr-xr-x  21 root  wheel    714 Jul 29 21:56 ./
drwxr-xr-x   5 root  wheel    170 Jul 29 21:56 ../
drwxr-xr-x   7 root  wheel    238 Jul 29 21:56 backward/
-rw-r--r--   2 root  wheel   3360 Sep 21 15:25 debug.h
-rw-r--r--   2 root  wheel   5553 Sep 21 15:25 defines.h
-rw-r--r--   2 root  wheel    881 Sep 21 15:25 digest.h
-rw-r--r--   2 root  wheel   7628 Sep 21 15:25 dl.h
-rw-r--r--   2 root  wheel  14123 Sep 21 15:25 encoding.h
-rw-r--r--   2 root  wheel  32904 Sep 21 15:25 intern.h
-rw-r--r--   2 root  wheel   5869 Sep 21 15:25 io.h
-rw-r--r--   2 root  wheel   4522 Sep 21 15:25 missing.h
-rw-r--r--   2 root  wheel  37617 Sep 21 15:25 oniguruma.h
-rw-r--r--   2 root  wheel   1502 Sep 21 15:25 re.h
-rw-r--r--   2 root  wheel    890 Sep 21 15:25 regex.h
-rw-r--r--   2 root  wheel  49734 Sep 21 15:25 ruby.h
-rw-r--r--   2 root  wheel   4651 Sep 21 15:25 st.h
-rw-r--r--   2 root  wheel    374 Sep 21 15:25 subst.h
-rw-r--r--   2 root  wheel   1102 Sep 21 15:25 thread.h
-rw-r--r--   2 root  wheel   2139 Sep 21 15:25 util.h
-rw-r--r--   2 root  wheel   1968 Sep 21 15:25 version.h
-rw-r--r--   2 root  wheel   1794 Sep 21 15:25 vm.h

安装过程中是否不小心删除了一个文件?Yosemite版本是否自带有错误的Ruby头文件集?

如何最好地解决这个问题?我只需在那里解压源代码以获取正确的标头吗?


你重新安装了Xcode工具吗?系统升级可能会强制要求这样做。 - the Tin Man
我重新安装了Xcode命令行工具,但仍然没有ruby/config.h文件。 - isaacs
1
我认为你没有安装正确的Xcode。请注意路径中的目录:MacOSX10.9.sdk。我希望能看到关于10.10的内容。 - CDub
CDub!太好了。我重新安装了Xcode 6.0.1,现在它似乎可以工作了,并且从完全不同的位置获取ruby.h。感谢您的提示! - isaacs
9个回答

18

需要注意的是:我在升级到“OS X El Capitan”后遇到了这个问题。通过运行“xcode-select --install”安装命令行工具后,我的Ruby构建环境又恢复正常了。


17

对于已经从Apple开发者网站安装了Xcode的人,运行xcode-select --install无法生效,因为它会提示Xcode已经安装(Xcode已经捆绑了CommandLineTools)。

在我这种情况下,我通过从同一位置下载相应的CommandLineTools,执行它,然后转到/Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg并执行它来解决问题。


16
cd /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/ruby
sudo ln -s ../universal-darwin15/ruby/config.h ./config.h

更新2014年10月18日Nicholas Tsipanov的答案。


这在我的OS X El Capitan 10.11.6上无法工作;没有这样的文件或目录。我不得不像Jesus描述的那样运行“'xcode-select --install'”。 - user5359531
也许你的 MacOSX10.11.sdkuniversal-darwin15 需要是正确的路径。在确保正确的路径后,它对我起作用了。 - Taku

12

6
如果您使用Homebrew,brew install ruby是一个快速的解决方法(它会为您提供一个与Xcode中的Ruby安装不同的全新Ruby安装)。

1
如果你使用的是bash或其他需要将其导向其他地方的shell,请执行以下操作:@AboozarRajabi echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.zshrc - Jadam
谢谢,我通过升级 Ruby 和 Rails 到最新版本解决了问题(缺失的 gem 已经重新安装)。 - Aboozar Rajabi
这样做有可能会破坏其他假定你正在使用操作系统自带版本的程序,不是吗? - Dielson Sales

4

试试这个:

cd /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/ruby
sudo ln -s ../universal-darwin13/ruby/config.h ./config.h

1
我正在运行Mojave 10.14.6。这里的答案解决了我的问题:https://dev59.com/MVYO5IYBdhLWcg3wF9wg#58084238 解决方案:
sudo rm -rf /Library/Developer/CommandLineTools
xcode-select --install
sudo xcodebuild -license accept
open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg 

1
Xcode在升级中出了问题。我打开Xcode(否则从不打开),它抱怨缺少各种组件。所以我让它自己修复,现在一切都好了。感谢评论中的CDub指出这可能是奇怪问题的潜在来源。

0

通过指向正确的Xcode开发工具路径进行修复。

之前的错误(请注意路径为Xcode711.app而不是Xcode.app)

/Applications/Xcode711.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/ruby/ruby.h:24:10:

运行

sudo xcode-select -s /Applications/Xcode.app/Contents/Developer

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