为什么我在 CentOS 7 上编译 Ruby 3.2 时出错?

问题描述 投票:0回答:2

我尝试使用 rbenv 的 ruby-build 插件构建 Ruby 3.2,但出现一些奇怪的编译错误:

compiling bignum.c
In file included from vm_core.h:164:0,
                 from iseq.h:14,
                 from mini_builtin.c:3,
                 from miniinit.c:51:
thread_pthread.h:109:39: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘struct’
 RUBY_EXTERN RB_THREAD_LOCAL_SPECIFIER struct rb_execution_context_struct *ruby_current_ec;
                                       ^
In file included from iseq.h:14:0,
                 from mini_builtin.c:3,
                 from miniinit.c:51:
vm_core.h: In function ‘rb_current_execution_context’:
vm_core.h:1864:34: error: ‘ruby_current_ec’ undeclared (first use in this function)
     rb_execution_context_t *ec = ruby_current_ec;
                                  ^
vm_core.h:1864:34: note: each undeclared identifier is reported only once for each function it appears in

以下是完整日志:https://gist.github.com/tycooon/c077a1d99299469bd86131211c565ff7.

Ruby 3.1 在同一台机器上构建没有任何问题。可能是什么问题?

c ruby linux centos7
2个回答
14
投票

问题是 centos7 附带的 GCC 太旧了。在我的情况下,机器上有

devtoolset-7-gcc.x86_64
软件包可用,因此我可以使用以下命令安装 Ruby 3.2:

CC=/opt/rh/devtoolset-7/root/usr/bin/gcc rbenv install 3.2.0 -v

希望这对某人有帮助。


0
投票

我在 CentOS 7 和 ruby 3.1.4 上也遇到了这个问题,@tycoon 的解决方案也在这里提供了解决方案。为了更完整,我将添加以下内容:

# As root
yum install centos-release-scl-rh
yum install devtoolset-7-gcc-c++
# As deploying user
CC=/opt/rh/devtoolset-7/root/usr/bin/gcc rbenv install 3.1.4 -v
© www.soinside.com 2019 - 2024. All rights reserved.