I try to build Ruby 3.2 using ruby-build plugin for rbenv but get some strange compilation error:
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
Here is the full log: https://gist.github.com/tycooon/c077a1d99299469bd86131211c565ff7.
Ruby 3.1 builds without any problems on the same machine. What could be the problem?
The problem was centos7 being shipped with too old GCC. There was devtoolset-7-gcc.x86_64 package available on the machine in my case, so I was able to install Ruby 3.2 using the following command:
CC=/opt/rh/devtoolset-7/root/usr/bin/gcc rbenv install 3.2.0 -v
Hope this helps someone.
As others have pointed out, the culprit is outdated version of GCC. To resolve the issue, follow the following steps to install and activate an newer version of GCC.
Enable a Software Repository with a Newer GCC Version:
sudo yum install centos-release-scl
Install a Newer GCC Version:
sudo yum install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
Activate the Newer GCC Version:
scl enable devtoolset-9 bash
Confirm that the new version of GCC is activated:
gcc --version
You'll see something like this:
gcc (GCC) 9.3.1 20200408 (Red Hat 9.3.1-2)
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Make the dev tools selection permanent:
Place the following code in /etc/profile or /etc/bashrc:
source scl_source enable devtoolset-9
Then run the appropriate source command below:
source /etc/profile
source /etc/bashrc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With