Why do gems with native extensions fail to build on Ubuntu? - ruby

I can run bundle install on my Mac without a problem, but when I run it on my Ubuntu build server it fails with the following output:
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/var/lib/jenkins/.rvm/rubies/ruby-1.9.3-p385-dev/bin/ruby extconf.rb
creating Makefile
make
compiling native.c
native.c: In function ‘birch_edge_initialize’:
native.c:42:8: warning: unused variable ‘direction’ [-Wunused-variable]
native.c:41:8: warning: unused variable ‘directed’ [-Wunused-variable]
native.c:40:8: warning: unused variable ‘node_b’ [-Wunused-variable]
native.c:39:8: warning: unused variable ‘node_a’ [-Wunused-variable]
native.c:58:1: warning: control reaches end of non-void function [-Wreturn-type]
linking shared-object birch/native.so
make install
/usr/bin/install -c -m 0755 native.so /var/lib/jenkins/jobs
/usr/bin/install -c -m 0755 native.so .
/usr/bin/install: 'native.so' and './native.so' are the same file
make: *** [-] Error 1
I'm using RVM, ruby version ruby-1.9.3-p385-dev.
The problem isn't specific to one gem either - removing birch results in the same type of error for bson with native extensions.

It seems this was caused by a bad RVM install. I initially installed rvm using apt (bad, bad idea), and it looks like the purge didn't clean everything up. Setting up a clean ec2 instance with a clean rvm install fixed it

Related

Ruby- error: Failed to build gem native extension. gcc: error: unrecognized command line option '-Wduplicated-cond'

I'm having issues with installing ruby gems in VScode via wsl ubuntu.
Specifically, rest-client, json, pry-byebug, and byebug, at the moment.
I was able to install the ruval gem and pry gem with no issues.
I'm not sure if some are lacking gem dependencies, need to be upgraded, or the filepath needs to change somehow.
I noticed the Ubuntu wsl terminal file path is "/mnt/C". May have something to do with it?
I think C/ is just regular windows, and /mnt/C is Ubuntu's version of the same, to access the C/ windows file path.
I keep getting messages like the below in my terminal :
// ♥ gem install json
Building native extensions. This could take a while...
/usr/share/rvm/rubies/ruby-2.6.1/lib/ruby/2.6.0/open3.rb:213: warning: Insecure world writable dir /mnt/c in
PATH, mode 040777
ERROR: Error installing json:
ERROR: Failed to build gem native extension.
current directory: /home/mjj4685mjj/.rvm/gems/ruby-2.6.1/gems/json-2.5.1/ext/json/ext/generator
/usr/share/rvm/rubies/ruby-2.6.1/bin/ruby -I /usr/share/rvm/rubies/ruby-2.6.1/lib/ruby/site_ruby/2.6.0 -r ./siteconf20210404-8832-c0i3v3.rb extconf.rb
creating Makefile
current directory: /home/mjj4685mjj/.rvm/gems/ruby-2.6.1/gems/json-2.5.1/ext/json/ext/generator
make DESTDIR\= clean
current directory: /home/mjj4685mjj/.rvm/gems/ruby-2.6.1/gems/json-2.5.1/ext/json/ext/generator
make DESTDIR\=
compiling generator.c
gcc: error: unrecognized command line option '-Wduplicated-cond'
gcc: error: unrecognized command line option '-Wmisleading-indentation'
gcc: error: unrecognized command line option '-Wrestrict'
gcc: error: unrecognized command line option '-Wimplicit-fallthrough=0'
make: *** [Makefile:244: generator.o] Error 1
make failed, exit code 2
Gem files will remain installed in /home/mjj4685mjj/.rvm/gems/ruby-2.6.1/gems/json-2.5.1 for inspection.
Results logged to /home/mjj4685mjj/.rvm/gems/ruby-2.6.1/extensions/x86_64-linux/2.6.0/json-2.5.1/gem_make.out[21:58:57]
// ♥ Sandbox (main)
It wasn't a /mnt/c/ path issue :
warning: Insecure world writable dir /mnt/c in PATH, mode 040777
The gems failed to compile and fully install because I had an outdated version of 'gcc' (Homebrew).:
compiling generator.c
gcc: error: unrecognized command line option '-Wduplicated-cond'
gcc: error: unrecognized command line option '-Wmisleading-indentation'
gcc: error: unrecognized command line option '-Wrestrict'
gcc: error: unrecognized command line option '-Wimplicit-fallthrough=0'
make: *** [Makefile:244: generator.o] Error 1
make failed, exit code 2
SOLUTION:
In terminal run: brew outdated ...and check to see if 'gcc' or 'g++' has any out-of-date
features.
Then run: brew upgrade
(Source: https://docs.brew.sh/FAQ)
Once upgrade installation was complete I was able to install gems as normal and all my programs ran just fine.

Issues building the libffi gem native extension when trying to install Jekyll on macOS Catalina

EDIT: I wrote up a more detailed solution on my blog here if you want to walk through all the steps.
I'm trying to install Jekyll via gem install Jekyll on macOS Catalina using Ruby install via homebrew and located at /usr/local/opt/ruby/bin/ruby and I'm running into the following error
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
current directory:
/Users/foobar/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/ffi-1.9.21/ext/ffi_c
/Users/foobar/.rbenv/versions/2.5.1/bin/ruby -r ./siteconf20181118-49440-k8mjki.rb
extconf.rb
checking for ffi.h... no
checking for ffi.h in /usr/local/include,/usr/include/ffi... no
checking for shlwapi.h... no
checking for rb_thread_blocking_region()... no
checking for rb_thread_call_with_gvl()... yes
checking for rb_thread_call_without_gvl()... yes
creating extconf.h
creating Makefile
current directory:
/Users/foobar/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/ffi-1.9.21/ext/ffi_c
make "DESTDIR=" clean
current directory:
/Users/foobar/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/ffi-1.9.21/ext/ffi_c
make "DESTDIR="
Running autoreconf for libffi
autoreconf: Entering directory `.'
autoreconf: configure.ac: not using Gettext
autoreconf: running: aclocal -I m4 --output=aclocal.m4t
Can't exec "aclocal": No such file or directory at
/usr/local/Cellar/autoconf/2.69/share/autoconf/Autom4te/FileUtils.pm line 326.
autoreconf: failed to run aclocal: No such file or directory
make: ***
["/Users/foobar/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/ffi-1.9.21/ext/ffi_c/libffi-x86_64-darwin18"/.libs/libffi_convenience.a]
Error 1
make failed, exit code 2
Gem files will remain installed in
/Users/foobar/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/ffi-1.9.21 for inspection.
Results logged to
/Users/foobar/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/extensions/x86_64-darwin-18/2.5.0-static/ffi-1.9.21/gem_make.out
An error occurred while installing ffi (1.9.21), and Bundler cannot continue.
I've already tried updating my Xcode Command Line tools via xcode-select --install but I got back the following message:
xcode-select: error: command line tools are already installed, use "Software Update" to install updates
Does anyone know how I can build libffi on my machine so that I Jekyll can use it as a dependency?
Aaaaaand I figured it out! Credit to #ffleming here. Here's what you need to do:
reinstall libffi on brew using brew reinstall libffi
add the new brew-installed libffi flags to your shell instance, e.g.
export LDFLAGS="-L/usr/local/opt/libffi/lib"
export PKG_CONFIG_PATH="/usr/local/opt/libffi/lib/pkgconfig"
Run gem install jekyll and you should be sorted!

rbenv : BUILD FAILED when Install Ruby 2.2.3 on UBUNTU 14.04 (x86_64)

I am trying to install ruby 2.2.3, previously I have installed ruby 2.2.2,
rbenv versions
system
* 2.2.2 (set by /home/emen/.ruby-version)
jruby-1.7.20
jruby-9.0.0.0.pre2Build
I got a problem when tried to install Ruby 2.2.3, got build failed below :
rbenv install 2.2.3
Downloading ruby-2.2.3.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.2/ruby-2.2.3.tar.bz2 Installing ruby-2.2.3...
BUILD FAILED (Ubuntu 14.04 using ruby-build 20160111-27-g06f1254)
Inspect or clean up the working tree at /tmp/ruby-build.20160127112741.26444 Results logged to /tmp/ruby-build.20160127112741.26444.log
I have inspected log, just copy a part of suspect since another checking and compiling process were fine :
linking shared-object objspace.so
make[2]: Leaving directory `/tmp/ruby-build.20160127112741.26444/ruby-2.2.3/ext/objspace'
compiling ossl_ssl.c
make[2]: Entering directory `/tmp/ruby-build.20160127112741.26444/ruby-2.2.3/ext/pathname'
compiling pathname.c
ossl_ssl.c:141:27: error: ‘SSLv3_method’ undeclared here (not in a function)
OSSL_SSL_METHOD_ENTRY(SSLv3),
^
ossl_ssl.c:119:69: note: in definition of macro ‘OSSL_SSL_METHOD_ENTRY’
#define OSSL_SSL_METHOD_ENTRY(name) { #name, (SSL_METHOD *(*)(void))name##_method }
^
ossl_ssl.c:142:27: error: ‘SSLv3_server_method’ undeclared here (not in a function)
OSSL_SSL_METHOD_ENTRY(SSLv3_server),
^
ossl_ssl.c:119:69: note: in definition of macro ‘OSSL_SSL_METHOD_ENTRY’
#define OSSL_SSL_METHOD_ENTRY(name) { #name, (SSL_METHOD *(*)(void))name##_method }
^
ossl_ssl.c:143:27: error: ‘SSLv3_client_method’ undeclared here (not in a function)
OSSL_SSL_METHOD_ENTRY(SSLv3_client),
^
ossl_ssl.c:119:69: note: in definition of macro ‘OSSL_SSL_METHOD_ENTRY’
#define OSSL_SSL_METHOD_ENTRY(name) { #name, (SSL_METHOD *(*)(void))name##_method }
^
make[2]: *** [ossl_ssl.o] Error 1
make[2]: Leaving directory `/tmp/ruby-build.20160127112741.26444/ruby-2.2.3/ext/openssl'
make[1]: *** [ext/openssl/all] Error 2
make[1]: *** Waiting for unfinished jobs....
installing default pathname libraries
linking shared-object date_core.so
make[2]: Leaving directory `/tmp/ruby-build.20160127112741.26444/ruby-2.2.3/ext/date'
linking shared-object pathname.so
make[2]: Leaving directory `/tmp/ruby-build.20160127112741.26444/ruby-2.2.3/ext/pathname'
linking shared-object nkf.so
make[2]: Leaving directory `/tmp/ruby-build.20160127112741.26444/ruby-2.2.3/ext/nkf'
make[1]: Leaving directory `/tmp/ruby-build.20160127112741.26444/ruby-2.2.3'
make: *** [build-ext] Error 2
I have tried to follow this
rbenv install ruby BUILD FAILED
I have run this :
sudo apt-get install libffi-dev
or
sudo apt-get install git-core curl
zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev
libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev
python-software-properties libffi-dev
and
curl -fsSL https://gist.github.com/ekr1/7313abef4348daa038dd.txt |
rbenv install --patch 2.2.3
but still no luck, I might miss something, appreciating your help. Thanks!
I have fixed this build failed by patching from https://gist.github.com/mislav/055441129184a1512bb5/
executed this :
curl -fsSL https://gist.github.com/mislav/055441129184a1512bb5.txt |
rbenv install --patch 2.2.3
this looks like an openssl problem. The SSL_v3 not defined means that you don't have it or you have an older library.
Try:
rvm pkg install openssl
rvm install 2.2.3 --with-openssl-dir=$HOME/.rvm/usr

Install gem gives "Failed to build gem native extension."

I did: sudo apt-get install ruby ruby-dev.
And i run: sudo gem install jekyll.
But it gives this output:
Building native extensions. This could take a while... ERROR: Error
installing jekyll: ERROR: Failed to build gem native extension.
/usr/bin/ruby2.1 -r ./siteconf20151018-15792-1gfjwox.rb extconf.rb creating Makefile
make "DESTDIR=" clean sh: 1: make: not found
make "DESTDIR=" sh: 1: make: not found
make failed, exit code 127
Gem files will remain installed in
/var/lib/gems/2.1.0/gems/fast-stemmer-1.0.2 for inspection. Results
logged to
/var/lib/gems/2.1.0/extensions/x86_64-linux/2.1.0/fast-stemmer-1.0.2/gem_make.out
You need to install make and other build tools first, run this:
sudo apt-get install build-essential
make: not found
This means that the program make (that is used to build libraries from code) is not present on your machine. You should try to install it with your package manager.
sudo apt-get cmake
might do the trick.
sudo apt-get install build-essential solves the issue for mysql gem failing due to make program failure for linux.

Can't install ruby-ldap under Windows/Cygwin

gem install ruby-ldap
Building native extensions. This could take a while...
ERROR: Error installing ruby-ldap:
ERROR: Failed to build gem native extension.
/usr/bin/ruby.exe extconf.rb
--with-ldap-dir=/usr
--with-openldap2
checking for ldap.h... yes
[...]
creating Makefile
make
gcc -I. -I. -I/usr/lib/ruby/1.8/i386-cygwin -I. ...
[...]
gcc -shared -s -o ldap.so ...
The configuration and the compilation works just fine. But the installation throws this error:
make install
/usr/bin/install -c -m 0755 ldap.so /usr/lib/ruby/gems/1.8/gems/ruby-ldap-0.9.12/lib
/usr/bin/install -c -m 644 ./lib/ldap/control.rb /usr/lib/ruby/gems/1.8/gems/ruby-ldap-0.9.12/lib/ldap
/usr/bin/install: `./lib/ldap/control.rb' and `/usr/lib/ruby/gems/1.8/gems/ruby-ldap-0.9.12/lib/ldap/control.rb' are the same file
Makefile:130: recipe for target `/usr/lib/ruby/gems/1.8/gems/ruby-ldap-0.9.12/lib/ldap/control.rb' failed
make: *** [/usr/lib/ruby/gems/1.8/gems/ruby-ldap-0.9.12/lib/ldap/control.rb] Error 1
./lib/ldap/control.rb and /usr/lib/ruby/gems/1.8/gems/ruby-ldap-0.9.12/lib/ldap/control.rb are indeed the same file, but why? Other gems with nativ bindings like mysql worked just fine. I reported this as a bug, but some other guy does not have the problem, so the package itself is intact.
If I download the gem and run:
ruby extconf.rb
make install
The Makefile runs just fine.
It must be my system/configuration. Whats going wrong here?
Wow, very oddly, I got this working by downgrading RubyGems and then upgrading it back. I downgraded it first to match a version (1.4.1) I had on another system that could install ruby-ldap just fine. I thought this might make it work on my current system, but I got the same error you did. I upgraded RubyGems back to what I had (1.8.15), then it all magically worked.
So:
$ gem update --system 1.4.1 # Downgrade to 1.4.1
...
$ gem update --system # Go back to current
...
$ gem install ruby-ldap
Building native extensions. This could take a while...
Successfully installed ruby-ldap-0.9.12
1 gem installed
Installing ri documentation for ruby-ldap-0.9.12...
Installing RDoc documentation for ruby-ldap-0.9.12...
$
FYI, I didn't have to use sudo because I'm using rvm and I was installing ruby-ldap into a per-project gemset.
If you are using Ubunty, try to perform
sudo apt-get install libsasl2-dev
More about it at https://github.com/alexey-chebotar/ruby-ldap/issues/7

Resources