Open choallin opened 5 years ago
I am having the same problem, gem install
looks in /snap/ruby/109/lib/ruby/include
:
$ gem install mysql2:0.3.21
Building native extensions. This could take a while...
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
current directory: /home/dayyan.lord/.gem/gems/mysql2-0.3.21/ext/mysql2
/snap/bin/ruby -r ./siteconf20190503-21474-2vfbku.rb extconf.rb
mkmf.rb can't find header files for ruby at /snap/ruby/109/lib/ruby/include/ruby.h
extconf failed, exit code 1
Gem files will remain installed in /home/dayyan.lord/.gem/gems/mysql2-0.3.21 for inspection.
Results logged to /home/dayyan.lord/.gem/extensions/x86_64-linux/2.3.0-static/mysql2-0.3.21/gem_make.out
The current location is:
$ ls /snap/ruby/109/include/ruby-2.3.0
ruby ruby.h x86_64-linux
@dayyan Have you found a solution to this?
@choallin Sorry, I have not. I ended up compiling Ruby copying the same commands the Dockerfile uses.
Hi all, Thanks to reporting this. I confirmed this is an issue of my package script for snap. I try to investigate json and mysql2 cases.
It seems like this could be the same problem I ran into trying to install eventmachine: https://github.com/eventmachine/eventmachine/issues/881
Based on the comments there, it sounds like bundle
is unable to find the Ruby headers.
After https://github.com/ruby/snap.ruby/pull/26, installing gem with ext failed with glibc version mismatch on Debian 10 (buster).
I think this does not happen on ubuntu-20.04, but I don't know how to resolve this issue on other platform without glibc 2.29.
vagrant@buster:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 10 (buster)
Release: 10
Codename: buster
vagrant@buster:~$ gem i json
Building native extensions. This could take a while...
ERROR: Error installing json:
ERROR: Failed to build gem native extension.
current directory: /home/vagrant/.gem/gems/json-2.6.0/ext/json/ext/parser
/snap/bin/ruby -I /snap/ruby/232/lib/ruby/3.0.0 -r ./siteconf20211020-3495-9mcx7g.rb extconf.rb
checking for rb_enc_raise() in ruby.h... *** 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.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/snap/ruby/232/bin/$(RUBY_BASE_NAME)
/snap/ruby/232/lib/ruby/3.0.0/mkmf.rb:471:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
from /snap/ruby/232/lib/ruby/3.0.0/mkmf.rb:564:in `try_link0'
from /snap/ruby/232/lib/ruby/3.0.0/mkmf.rb:582:in `try_link'
from /snap/ruby/232/lib/ruby/3.0.0/mkmf.rb:794:in `try_func'
from /snap/ruby/232/lib/ruby/3.0.0/mkmf.rb:1083:in `block in have_func'
from /snap/ruby/232/lib/ruby/3.0.0/mkmf.rb:971:in `block in checking_for'
from /snap/ruby/232/lib/ruby/3.0.0/mkmf.rb:361:in `block (2 levels) in postpone'
from /snap/ruby/232/lib/ruby/3.0.0/mkmf.rb:331:in `open'
from /snap/ruby/232/lib/ruby/3.0.0/mkmf.rb:361:in `block in postpone'
from /snap/ruby/232/lib/ruby/3.0.0/mkmf.rb:331:in `open'
from /snap/ruby/232/lib/ruby/3.0.0/mkmf.rb:357:in `postpone'
from /snap/ruby/232/lib/ruby/3.0.0/mkmf.rb:970:in `checking_for'
from /snap/ruby/232/lib/ruby/3.0.0/mkmf.rb:1082:in `have_func'
from extconf.rb:4:in `<main>'
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/home/vagrant/.gem/extensions/x86_64-linux/3.0.0/json-2.6.0/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in /home/vagrant/.gem/gems/json-2.6.0 for inspection.
Results logged to /home/vagrant/.gem/extensions/x86_64-linux/3.0.0/json-2.6.0/gem_make.out
vagrant@buster:~$ cat /home/vagrant/.gem/extensions/x86_64-linux/3.0.0/json-2.6.0/mkmf.log
"gcc -o conftest -I/snap/ruby/232/include/ruby-3.0.0/x86_64-linux -I/snap/ruby/232/include/ruby-3.0.0/ruby/backward -I/snap/ruby/232/include/ruby-3.0.0 -I. -O3 -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wduplicated-cond -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wwrite-strings -Wimplicit-fallthrough=0 -Wmissing-noreturn -Wno-cast-function-type -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-packed-bitfield-compat -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wsuggest-attribute=format -Wsuggest-attribute=noreturn -Wunused-variable -fPIC conftest.c -L. -L/snap/ruby/232/lib -Wl,-rpath,/snap/ruby/232/lib -L. -L/root/parts/ruby/install/usr/lib -L/root/parts/ruby/install/usr/lib/x86_64-linux-gnu -fstack-protector-strong -rdynamic -Wl,-export-dynamic -Wl,-rpath,/snap/ruby/232/lib -L/snap/ruby/232/lib -lruby -lm -lc"
/usr/bin/ld: /snap/ruby/232/lib/libruby.so: undefined reference to `log2@GLIBC_2.29'
/usr/bin/ld: /snap/ruby/232/lib/libruby.so: undefined reference to `log@GLIBC_2.29'
/usr/bin/ld: //snap/core20/current/lib/x86_64-linux-gnu/libpthread.so.0: undefined reference to `__twalk_r@GLIBC_PRIVATE'
/usr/bin/ld: /snap/ruby/232/lib/libruby.so: undefined reference to `pow@GLIBC_2.29'
/usr/bin/ld: /snap/ruby/232/lib/libruby.so: undefined reference to `exp@GLIBC_2.29'
collect2: error: ld returned 1 exit status
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main(int argc, char **argv)
4: {
5: return !!argv[argc];
6: }
/* end */
Seeing this as well, with a different set of gems - https://github.com/ruby/snap.ruby/issues/28
I have to work on an old rails 4.2 codebase. I have installed Ruby 2.3 as a snap package - I am trying to avoid rvm. Now, when I run bundle install it complains that it can't install the json gem. Here is the error message:
When I try to install just the gem with 'gem install json -v '1.8.6' --source 'https://rubygems.org/'' I get this error:
So, as far as I can tell the native extension is looking in the wrong directory for the ruby headers - I guess...