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

tyc*_*oon 11 c ruby linux centos7

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

\n
compiling bignum.c\nIn file included from vm_core.h:164:0,\n                 from iseq.h:14,\n                 from mini_builtin.c:3,\n                 from miniinit.c:51:\nthread_pthread.h:109:39: error: expected \xe2\x80\x98=\xe2\x80\x99, \xe2\x80\x98,\xe2\x80\x99, \xe2\x80\x98;\xe2\x80\x99, \xe2\x80\x98asm\xe2\x80\x99 or \xe2\x80\x98__attribute__\xe2\x80\x99 before \xe2\x80\x98struct\xe2\x80\x99\n RUBY_EXTERN RB_THREAD_LOCAL_SPECIFIER struct rb_execution_context_struct *ruby_current_ec;\n                                       ^\nIn file included from iseq.h:14:0,\n                 from mini_builtin.c:3,\n                 from miniinit.c:51:\nvm_core.h: In function \xe2\x80\x98rb_current_execution_context\xe2\x80\x99:\nvm_core.h:1864:34: error: \xe2\x80\x98ruby_current_ec\xe2\x80\x99 undeclared (first use in this function)\n     rb_execution_context_t *ec = ruby_current_ec;\n                                  ^\nvm_core.h:1864:34: note: each undeclared identifier is reported only once for each function it appears in\n
Run Code Online (Sandbox Code Playgroud)\n

这是完整的日志:https://gist.github.com/tycooon/c077a1d99299469bd86131211c565ff7

\n

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

\n

tyc*_*oon 19

问题是 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
Run Code Online (Sandbox Code Playgroud)

希望这对某人有帮助。