Ruby:slimにdiscordrbをインストールできた

Rubyの公式dockerイメージの一つruby:slimにDiscord botライブラリのdiscordrbをインストールしたかった。

解決

  • makeとg++パッケージをインストールする
    • C++のライブラリが足りてないっぽい
# apt update
# apt install g++ make
# gem install discordrb
  • build-essential にg++もmakeも含まれるので、build-essentialでも可
    • g++とmake (151MB)
    • build-essential (221MB)

エラー

$ docker run -it --rm ruby:slim bash
# gem install discordrb

Building native extensions. This could take a while...
ERROR: Error installing discordrb:
ERROR: Failed to build gem native extension.

current directory: /usr/local/bundle/gems/unf_ext-0.0.7.7/ext/unf_ext
/usr/local/bin/ruby -I /usr/local/lib/ruby/2.7.0 -r ./siteconf20200406-597-121o8d0.rb extconf.rb
checking for -lstdc++... 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=/usr/local/bin/$(RUBY_BASE_NAME)
--with-static-libstdc++
--without-static-libstdc++
--with-stdc++-dir
--without-stdc++-dir
--with-stdc++-include
--without-stdc++-include=${stdc++-dir}/include
--with-stdc++-lib
--without-stdc++-lib=${stdc++-dir}/lib
--with-stdc++lib
--without-stdc++lib
/usr/local/lib/ruby/2.7.0/mkmf.rb:471:in try_do': The compiler failed to generate an executable file. (RuntimeError)<br> <br> You have to install development tools first.<br> from /usr/local/lib/ruby/2.7.0/mkmf.rb:564:intry_link0'
from /usr/local/lib/ruby/2.7.0/mkmf.rb:582:in try_link'<br> from /usr/local/lib/ruby/2.7.0/mkmf.rb:801:intry_func'
from /usr/local/lib/ruby/2.7.0/mkmf.rb:1029:in block in have_library'<br> from /usr/local/lib/ruby/2.7.0/mkmf.rb:971:inblock in checking_for'
from /usr/local/lib/ruby/2.7.0/mkmf.rb:361:in block (2 levels) in postpone'<br> from /usr/local/lib/ruby/2.7.0/mkmf.rb:331:inopen'
from /usr/local/lib/ruby/2.7.0/mkmf.rb:361:in block in postpone'<br> from /usr/local/lib/ruby/2.7.0/mkmf.rb:331:inopen'
from /usr/local/lib/ruby/2.7.0/mkmf.rb:357:in postpone'<br> from /usr/local/lib/ruby/2.7.0/mkmf.rb:970:inchecking_for'
from /usr/local/lib/ruby/2.7.0/mkmf.rb:1024:in have_library'<br> from extconf.rb:6:in

'

To see why this extension failed to compile, please check the mkmf.log which can be found here:

/usr/local/bundle/extensions/x86_64-linux/2.7.0/unf_ext-0.0.7.7/mkmf.log

extconf failed, exit code 1

em files will remain installed in /usr/local/bundle/gems/unf_ext-0.0.7.7 for inspection.
Results logged to /usr/local/bundle/extensions/x86_64-linux/2.7.0/unf_ext-0.0.7.7/gem_make.out

logファイル

"gcc -o conftest -I/usr/local/include/ruby-2.7.0/x86_64-linux -I/usr/local/include/ruby-2.7.0/ruby/backward -I/usr/local/include/ruby-2.7.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/usr/local/lib -Wl,-rpath,/usr/local/lib -L. -fstack-protector-strong -rdynamic -Wl,-export-dynamic     -Wl,-rpath,/usr/local/lib -L/usr/local/lib -lruby  -lm   -lc"
 checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main(int argc, char **argv)
4: {
5:   return !!argv[argc];
6: }
/* end */