CentOS 7 で Ruby 3.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 は同じマシン上で問題なくビルドされます。何が問題なのでしょうか?
解決策
問題は、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
これが誰かの役に立てば幸いです。