appleLover appleLover - 1 year ago 60
Ruby Question

Bundle Install Rsruby Fails, But Gem Install Succeeds

I have ruby2.2, ubuntu 14.04.4 LTS, and I want to install the rsruby gem. Everything is set up, and all my other gems are set up, with "sudo bundle install." But rsruby keeps crashing when I try to install it like that. How do I debug it and make it work?

I have a script I run which runs this command

sudo bundle config build.rsruby "--with-R-include=/usr/share/R/include --with_cflags=\"-fPIC -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wall -fno-strict-aliasing\""

Then I run "sudo bundle install" and it crashes on RSRuby:

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

/usr/bin/ruby2.2 -r ./siteconf20161028-31919-l2ks0n.rb extconf.rb
--with-R-include=/usr/share/R/include --with_cflags=\"-fPIC -g -O2
-fstack-protector --param=ssp-buffer-size=4 -Wformat -Wall
checking for main() in -lR... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.

from /usr/lib/ruby/2.2.0/mkmf.rb:541:in `try_link0'
from /usr/lib/ruby/2.2.0/mkmf.rb:556:in `try_link'
from /usr/lib/ruby/2.2.0/mkmf.rb:735:in `try_func'
from /usr/lib/ruby/2.2.0/mkmf.rb:992:in `block in find_library'
from /usr/lib/ruby/2.2.0/mkmf.rb:911:in `block in checking_for'
from /usr/lib/ruby/2.2.0/mkmf.rb:351:in `block (2 levels) in postpone'
from /usr/lib/ruby/2.2.0/mkmf.rb:321:in `open'
from /usr/lib/ruby/2.2.0/mkmf.rb:351:in `block in postpone'
from /usr/lib/ruby/2.2.0/mkmf.rb:321:in `open'
from /usr/lib/ruby/2.2.0/mkmf.rb:347:in `postpone'
from /usr/lib/ruby/2.2.0/mkmf.rb:910:in `checking_for'
from /usr/lib/ruby/2.2.0/mkmf.rb:988:in `find_library'
from extconf.rb:15:in `<main>'

extconf failed, exit code 1

Gem files will remain installed in
/var/lib/gems/2.2.0/bundler/gems/rsruby-e72a8dc61617 for inspection.
Results logged to

An error occurred while installing rsruby (0.5.5), and Bundler cannot

But if I run

sudo gem install rsruby -- --with-R-dir=/usr/lib/R --with-R-include=/usr/share/R/include --with_cflags="-fPIC -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wall -fno-strict-aliasing"

Then it successfully installs

Fetching: rsruby- (100%)
Building native extensions with: '--with-R-dir=/usr/lib/R --with-R-include=/usr/share/R/include --with_cflags=-fPIC -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wall -fno-strict-aliasing'
This could take a while...
Successfully installed rsruby-
Parsing documentation for rsruby-
Installing ri documentation for rsruby-
Done installing documentation for rsruby after 0 seconds
1 gem installed

SO, my question is, how do I debug this? And how do I get it working with bundle install? Thanks!

UPDATE, as matt pointed out in the comments, the version of the rsruby gem installed by the two commands was different. if i change my Gemfile to specify bundle to install version "" then "sudo bundle install" installs successfully. however, i need version "0.5.5". my Gemfile is currently set up like this, "gem 'rsruby', github: 'custora/rsruby'" and must get version 0.5.5. so why would install correctly, but not 0.5.5?

UPDATE, mkmf.log

gcc -o conftest -I/usr/include/x86_64-linux-gnu/ruby-2.1.0 -I/usr/include/ruby-2.1.0/ruby/backward -I/usr/include/ruby-2.1.0 -I. -I/usr/share/R/include -D_FORTIFY_SOURCE=2 "-g conftest.c -L. -L/usr/lib/x86_64-linux-gnu -L. -Wl,-Bsymbolic-functions -Wl,-z,relro -L/build/ruby2.1-3vrZnx/ruby2.1-2.1.9/debian/lib -fstack-protector -rdynamic -Wl,-export-dynamic -lruby-2.1 -lpthread -lgmp -ldl -lcrypt -lm -lc"
sh: 1: Syntax error: Unterminated quoted string
checked program was:
/* begin */
1: #include "ruby.h"
3: int main(int argc, char **argv)
4: {
5: return 0;
6: }
/* end */

Answer Source

Okay so there were a few different things going on here. I will document them all here in case someone else who needs to use rsruby comes across this. First, as Matt pointed out, bundle install and gem install were trying to install two different versions of rsruby. Second, I had to change this script which I ran to set the bundle configuration options, this script did NOT work. To make this work, I replaced the \" with '


# Does /usr/bin/gem link to /usr/bin/gem2.1 ?
# gem install bundler -v 1.6.0.rc2
sudo bundle config build.rsruby "--with-R-include=/usr/share/R/include --with-cflags=\"-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -fPIC\""

The above two steps made rsruby install. But after that I kept getting segfault errors anyway. The problem seems to have been either an old distro of ubuntu, or the fact that since it was an old distro of ubuntu, I had to use brightbox repo to get a more recent version of ruby. In any case, after updating to a current distro of linux which had a current version of ruby, it worked.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download