Economy of Effort

Twitter LinkedIn GitHub Mail RSS

Error Building Ruby 1.8.7 With Rbenv/Ruby Install On Linux With Glibc >= 2.14

If you’re using rbenv and ruby-build on a Linux that has updated to glibc 2.14 or newer, you may have encountered an error like this when attempting to build an older version of MRI:

$ rbenv install 1.8.7-p357 rbenv: 1.9.3-p194
Installing ruby-1.8.7-p357…
BUILD FAILED
Inspect or clean up the working tree at /tmp/ruby-build.20120508145707.21228
Results logged to /tmp/ruby-build.20120508145707.21228.log
Last 10 log lines:
callback.func:79:24: error: ‘proc’ undeclared here (not in a function)
callback.func:79:39: error: ‘argc’ undeclared here (not in a function)
callback.func:79:45: error: ‘argv’ undeclared here (not in a function)
callback.func:82:1: error: expected identifier or ‘(’ before ‘}’ token
dl.c:106:1: error: expected ‘;’, ‘,’ or ‘)’ before ‘static’
cp ../.././ext/dl/lib/dl/import.rb ../../.ext/common/dl
make[1]: [dl.o] Error 1
make[1]: Waiting for unfinished jobs….
make[1]: Leaving directory `/tmp/ruby-build.20120508145707.21228/ruby-1.8.7-p357/ext/dl'
make: *** [all] Error 1

The issue isn’t specific to ruby-build or rbenv, but rather is an issue with building Ruby after upgrading glibc to 2.14:

This is caused by the fact that the generated file callback.func is corrupt. The corruption is triggered by a recent glibc change:

http://sourceware.org/git/?p=glibc.git;a=commitdiff;h=glibc-2.13-161-gfcabc0f

which was to fix a POSIX compatibility issue:

http://sourceware.org/bugzilla/show_bug.cgi?id=12724

Patches are provided to manually patch the Ruby source before building, but what if you’re using something like rbenv and ruby-install, instead of building Ruby manually?

This Gist, from GitHub user kungfoo, provides a ruby-build definition for building Ruby 1.8.7-p358 with the required patch for building on a system with the updated glibc.

To date, I had only used rbenv and ruby-build to build Rubies from ruby-build’s included definitions. Turns out, it’s quite easy to use this definition, once I realized that that’s what this was.

Simply do the following:

$ vim /tmp/1.8.7-p358-with-rogue-stdout-patch
... paste contents of Gist into file, save and exit ...
$ rbenv install /tmp/1.8.7-p358-with-rogue-stdout-patch

Note, the filename will be the name that rbenv uses to identify this Ruby, so if you don’t want the name to be “1.8.7-p358-with-rogue-stdout-patch”, name the file to match the name you prefer.

Comments