ruby - 是否可以使用 Bundler 安装 gem,并告诉它对特定 gem 使用特定编译器?

标签 ruby gcc bundler osx-yosemite

我无法在运行 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)构建,我认为它会起作用。

我尝试将我的 CCCXX 变量设置为 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/

相关文章:

gcc - 编译时间障碍 - 编译器代码重新排序 - gcc 和 pthreads

ruby-on-rails-3 - 未初始化的常量 Psych::Syck with Rails 3/Rubygems 1.6.2/bundler 1.0.10

ruby - -bash :/usr/bin/bundle:/System/Library/Frameworks/Ruby. framework/Versions/1.8/usr/bin/ruby: 错误的解释器:没有这样的文件或目录

ruby - 构建后 Gem 中缺少文件

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

ruby - 将域与 URL 匹配

c - 将匿名参数传递给 C 中的函数

c++ - clang 错误 : c++/4. 8/bits/STL_iterator_base_types.h:227:29: 错误: 'iterator_category' 中没有名为 'std::iterator_traits<unsigned long>' 的类型

ruby-on-rails - 为什么我无法在 Ruby On Rails 上安装 mysql2?

RVM/Bundler/Capistrano 的 Python 替代品