我无法在运行 Yosemite 的新 Mac 上安装 gem 包,因为一个 gem 只能使用操作系统附带的 C 编译器进行安装,而另一个 gem 则需要 Homebrew 中的 C 编译器。
我根本无法工作,只是因为所谓的新 gcc
版本 4.9.1
出现了这个错误:
cc1: error: -Werror=shorten-64-to-32: no option -Wshorten-64-to-32
我不明白这个错误意味着什么,也不明白如何告诉编译器忽略它。甚至这是可能的
我的具体情况是在 v8
gem 上运行 bundle install
失败:
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
/Users/me/.rbenv/versions/2.1.0/bin/ruby extconf.rb
creating Makefile
Compiling v8 for x64
Using python 2.7.6
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Unable to find a compiler officially supported by v8.
It is recommended to use GCC v4.4 or higher
Using compiler: g++
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Unable to find a compiler officially supported by v8.
It is recommended to use GCC v4.4 or higher
../src/cached-powers.cc:136:18: error: unused variable 'kCachedPowersLength' [-Werror,-Wunused-const-variable]
static const int kCachedPowersLength = ARRAY_SIZE(kCachedPowers);
新版本 XCode
附带的 g++
编译器给出的版本如下:
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
所以,4.2
已经很旧了。如果我可以配置一个 gem 来使用 Homebrew gcc
(即 4.9.1)构建,我认为它会起作用。
我尝试将我的 CC
和 CXX
变量设置为 Homebrew gcc
,但是 Nokogiri
gem 会未安装并出现上述第一条错误消息。 Yosemite cc 安装了更多的 gem ,也许留下了最好的路线。我不知道。
最佳答案
使用 bundle 配置,您可以传递编译器标志。更多信息将有助于为您提供更好的答案。
参见:http://bundler.io/man/bundle-config.1.html
我刚刚发现这个:How to install therubyracer gem on 10.10 Yosemite? 这将为您提供 libv8,然后 v8 应该编译并安装 gem。在研究这个问题时,我发现了围绕 Yosemite 和 clang/gcc 等的大量问题,包括对 nokogiri 的修复:Installing Nokogiri on OSX 10.10 Yosemite
基本上,据我所知,yosemite gcc 编译器太过时了(原始错误意味着编译器无法识别给定的编译选项,即 gcc 4.2 中不存在该功能)。我认为最好的解决方案是通过自制程序和安装路径等安装更新的 gcc,这样 gem 安装仅使用自制程序版本。
希望这些链接有所帮助。
关于ruby - 是否可以使用 Bundler 安装 gem,并告诉它对特定 gem 使用特定编译器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26452443/