我试图运行gem安装json,但出现了以下错误

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb 
creating Makefile

make "DESTDIR=" clean

make "DESTDIR="
compiling generator.c
linking shared-object json/ext/generator.bundle
clang: error: unknown argument: '-multiply_definedsuppress' [-Wunused-command-line-argument-hard-error-in-future]
clang: note: this will be a hard error (cannot be downgraded to a warning) in the future
make: *** [generator.bundle] Error 1

make failed, exit code 2

Gem files will remain installed in /opt/boxen/repo/.bundle/ruby/2.0.0/gems/json-1.8.0 for inspection.
Results logged to /opt/boxen/repo/.bundle/ruby/2.0.0/extensions/universal-darwin-13/2.0.0/json-1.8.0/gem_make.out

我用的是:

Os X:10.9.2

推荐答案

在将Xcode升级到5.1之后,我遇到了完全相同的问题,而苹果的消息并不好.从Xcode 5.1 Release Notes开始:

  • Xcode 5.1中的Apple LLVM编译器将无法识别的命令行选项视为错误.这个问题在构建Python本机扩展和Ruby Gems时就已经出现了,目前在Ruby Gems中指定了一些无效的编译器选项.

需要更改使用无效编译器选项的项目以删除这些选项.为了帮助简化转换,编译器将临时接受一个选项,将错误降级为警告:

-Wno-error=unused-command-line-argument-hard-error-in-future

要解决此问题,请设置ARCHFLAGS环境变量,将错误降级为警告.

ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future gem install GemName

似乎所有违反编译器选项的gem都必须更新才能使用有效选项.明确规定:This option [downgrading error to warning] will not be supported in the future.

我们看到的叮当声(this will be a hard error (cannot be downgraded to a warning) in the future)对应于发行说明中宣布的更改.


要具体回答您的问题,请使用以下方法安装json gem:

ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future gem install json

然而,请注意,这只是一个临时修复.

Ruby相关问答推荐

用函数组合枚举器的Ruby方法

VS Code Prettier 打破哈希访问

如何从 DateTime 值中删除区域?

Symfony 2assets资源过滤器异常中的指南针

使用 RSpec 存根 Time.now

将ruby数组转换为连续对数组

您如何将 Cucumber 场景标记为待处理

为什么 RuboCop 建议用 Array.new 替换 .times.map?

Ruby:获取不带扩展名的文件名

Ruby数组限制方法

文字数字中的下划线是什么意思?

在 Ruby 中将散列扁平化为字符串

为什么 Ruby 的 Date 类会自动加载,但 DateTime 不会?

在 Ruby 中查找内存泄漏的原因

如何合并 Ruby 哈希

如何在 Ruby 中编写复杂的多行 if 条件?

Ruby 删除目录

Ruby Style:如何判断嵌套的哈希元素是否存在

如何创建一个 Gemfile?

Docker for Mac - mkmf.rb 找不到 ruby​​ 的头文件