Gem::Ext::BuildError: 错误:在CenOS 6.5上构建本地宝石扩展失败。

4
安装Redmine。 我已经尝试过,
bundle install --without development test postgresql sqlite

但是发生了错误。

Gem::Ext::BuildError:错误:无法构建本地宝石扩展。

current directory:
/usr/local/lib/ruby/gems/2.4.0/gems/json-1.8.3/ext/json/ext/generator
/usr/local/bin/ruby -r ./siteconf20161228-21055-1dxe9y9.rb extconf.rb
creating Makefile

current directory:
/usr/local/lib/ruby/gems/2.4.0/gems/json-1.8.3/ext/json/ext/generator
make "DESTDIR=" clean

current directory:
/usr/local/lib/ruby/gems/2.4.0/gems/json-1.8.3/ext/json/ext/generator
make "DESTDIR="
compiling generator.c
generator.c: In function ‘generate_json’:
generator.c:861: error: ‘rb_cFixnum’ undeclared (first use in this
function)
generator.c:861: error: (Each undeclared identifier is reported only
once
generator.c:861: error: for each function it appears in.)
generator.c:863: error: ‘rb_cBignum’ undeclared (first use in this
function)
At top level:
cc1: warning: unrecognized command line option "-Wno-self-assign"
cc1: warning: unrecognized command line option
"-Wno-constant-logical-operand"
cc1: warning: unrecognized command line option
"-Wno-parentheses-equality"
cc1: warning: unrecognized command line option
"-Wno-tautological-compare"
make: *** [generator.o] error 1

make failed, exit code 2

Gem files will remain installed in
/usr/local/lib/ruby/gems/2.4.0/gems/json-1.8.3 for inspection.
Results logged to
/usr/local/lib/ruby/gems/2.4.0/extensions/x86_64-linux/2.4.0-static/json-1.8.3/gem_make.out

An error occurred while installing json (1.8.3), and Bundler
cannot continue.
Make sure that `gem install json -v '1.8.3'` succeeds before
bundling.

所以,我尝试了gem install json -v '1.8.3',但是我没有解决它。

你介意读一下这个问题吗?

4个回答

4

Ruby 2.4非常新,实际上它只发布了3天。

由于Ruby 2.4中有几个重要的内部更改,因此许多gem(包括Redmine本身)可能尚未与此版本的Ruby兼容。

从您的错误消息来看,JSON gem确实需要适应Ruby 2.4中关于整数的一些更改。

现在您应该使用较旧的Ruby版本,例如Ruby 2.3.3。如http://www.redmine.org/projects/redmine/wiki/RedmineInstall#Ruby-interpreter所示,Redmine需要特定的Ruby版本,具体取决于Redmine的版本。


1
我明白了...这意味着Ruby 2.4不支持JSON 1.8.3。那么,是否有关于跟随Ruby版本的稳定gems列表的信息? 我想知道如何搜索关键词以自己解决问题。 - Johnson
每个 gem 都实现了自己的兼容性机制。要确保兼容性,您需要阅读文档、尝试或询问维护者。您还可以在 Google 上搜索“[gemname] ruby 2.4”或“[gemname] [error message]”。至于 json gem,它们支持 Ruby 2.4 自 json 2.0 起。所需的更改已经被回溯到了1.8分支,但尚未发布。 - Holger Just

0

我现在遇到了同样的问题。 要解决这个问题,请手动使用gem install安装最新版本的bundlerrmagick,使用gem update更新其他所有软件包以及bundle update。 这解决了json 1.8.3ruby 2.4的依赖关系。

但是之后我遇到了更多的问题。 似乎ruby 2.4对数字的解释进行了一些更改,这意味着它不再与rail 4.x兼容 (参见此文章)。 更新rails及其依赖项似乎还不可能,因为redmine需要protected_attributes,它依赖于 activemodel(<5.0,>=4.0.1)rails 5.x则依赖于 activemodel 5.x

如果更新破坏了向后兼容性,特别是对于编程语言,那总是很糟糕的 :(


-1

首次运行

gem install bundler

它安装了更新的bundler并解决了本地扩展依赖关系

然后运行

bundle install 

它应该解决你的问题


-1

看起来json gem在新的ruby版本(2.4+)中存在一个bug,makandracards的answer提出了一个简单易行的解决方案。

答案是更新json gem的版本以解决该bug并成功安装gem。因此,它使用--conservative选项更新json gem。

bundle update json --conservative


虽然这个链接可能回答了问题,但最好在此处包含答案的基本部分并提供参考链接。如果链接页面更改,仅有链接的答案可能会失效。- 来自审查 - kenlukas
好的,我会从现在开始更详细地阐述,但似乎这是一个简单的事情,不需要解释。 - icarus

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