Ruby-on-rails 如何安装 json gem - 无法构建 gem 本机扩展(mac 10.10)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29578142/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to install json gem - Failed to build gem native extension(mac 10.10)
提问by zwb
OS: Mac OS X 10.10.3 XCode: Latest with command line tools installed (version 6.3) Rails: version 4.2.1 Ruby: version 2.2.1
操作系统:Mac OS X 10.10.3 XCode:安装了命令行工具的最新版本(6.3 版) Rails:4.2.1 版 Ruby:2.2.1 版
I was trying to generate the routes for a project I am working on (been doing that on regular basis), when I got an error message, with a recommendation that I do bundle install and bundle exec. I did, and this time around, the process broke off while compiling the JSON Gem (version 1.7.7).
我正在尝试为我正在处理的项目生成路由(定期这样做),当我收到一条错误消息时,建议我执行 bundle install 和 bundle exec。我做到了,这一次,该过程在编译 JSON Gem(1.7.7 版)时中断了。
Doing some research on StackOverflow, the recommendation was to update the Xcode's command line tools, and I did, but that did not solve the problem.
在 StackOverflow 上做了一些研究,建议是更新 Xcode 的命令行工具,我做到了,但这并没有解决问题。
I tried installing the JSON version 1.7.7 separately, and it failed, telling me to look for the error log in:
我尝试单独安装 JSON 版本 1.7.7,它失败了,告诉我寻找错误登录:
/Users/zwb/.rvm/rubies/ruby-2.2.1/bin/ruby -r ./siteconf20150411-36070-1t083xl.rb extconf.rb
creating Makefile
make "DESTDIR=" clean
make "DESTDIR="
compiling generator.c
In file included from generator.c:1:
./../fbuffer/fbuffer.h:175:47: error: too few arguments provided to function-like macro invocation
VALUE result = rb_str_new(FBUFFER_PAIR(fb));
^
/Users/zwb/.rvm/rubies/ruby-2.2.1/include/ruby-2.2.0/ruby/intern.h:793:9: note: macro 'rb_str_new' defined here
#define rb_str_new(str, len) __extension__ ( \
^
In file included from generator.c:1:
./../fbuffer/fbuffer.h:175:11: warning: incompatible pointer to integer conversion initializing 'VALUE' (aka 'unsigned long') with an expression of type 'VALUE (const char *, long)' [-Wint-conversion]
VALUE result = rb_str_new(FBUFFER_PAIR(fb));
^ ~~~~~~~~~~
1 warning and 1 error generated.
make: *** [generator.o] Error 1
make failed, exit code 2
回答by RAJ
Sad, however, JSON-1.7.7 (and upto 1.8.1) is incompatiblewith Ruby-2.2.x. As you are using Ruby-2.2.1, it will not work for you.
然而,遗憾的是,JSON-1.7.7(以及最高 1.8.1)与 Ruby-2.2.x不兼容。由于您使用的是 Ruby-2.2.1,它对您不起作用。
There are 2 options for you:
有 2 个选项供您选择:
- Update your
jsongem to1.8.2version. -- Preferable - Edit
ruby-2.2.1/ext/json/fbuffer/fbuffer.hfile and replace problematic code withVALUE result = rb_str_new(FBUFFER_PTR(fb), FBUFFER_LEN(fb));. Look herefor details
- 将您的
jsongem更新到1.8.2版本。--优选 - 编辑
ruby-2.2.1/ext/json/fbuffer/fbuffer.h文件并将有问题的代码替换为VALUE result = rb_str_new(FBUFFER_PTR(fb), FBUFFER_LEN(fb));. 详情请看这里
回答by Robert
If you are using Ruby 2.2.0 or greater, the json gem will not compile properly. You can fix this by issuing bundle update json
如果您使用 Ruby 2.2.0 或更高版本,json gem 将无法正确编译。您可以通过发出来解决这个问题bundle update json
回答by Dan Hodgins
gem install json -v '1.8.2' worked for me.
gem install json -v '1.8.2' 对我有用。
回答by Ian
I encountered this problem as well, and none of the suggested fixes here solved it.
我也遇到了这个问题,这里建议的修复程序都没有解决它。
I was only able to resolve it by manually re-downloading and re-installing the appropriate version of the Xcode command line tools:
我只能通过手动重新下载并重新安装适当版本的 Xcode 命令行工具来解决它:
https://developer.apple.com/download/more/?name=command%20line%20tools
https://developer.apple.com/download/more/?name=command%20line%20tools
回答by Jason
This worked for me, since I downloaded basic Ruby by accident.
这对我有用,因为我不小心下载了基本的 Ruby。
1.
1.
Install the Ruby "Development Kit" here: http://rubyinstaller.org/downloads/Click the self-extracting file, and extract it here:
在此处安装 Ruby“开发工具包”:http: //rubyinstaller.org/downloads/单击自解压文件,并在此处解压:
C:\RubyDevKit
C:\RubyDevKit
(or somewhere else, but I had problems in other directories)
(或其他地方,但我在其他目录中遇到问题)
2.
2.
Open the cmd (terminal):
cd C:\RubyDevKit
ruby dk.rb init
ruby dk.rb install
打开cmd(终端):
cd C:\RubyDevKit
ruby dk.rb init
ruby dk.rb install
Source: http://jekyll-windows.juthilo.com/1-ruby-and-devkit/

