rnso
rnso

Reputation: 24623

Not able to load tk in Ruby

I am trying to run some tk code in Ruby, but it is not working. Following is the error:

iuser@debian:~$ irb
irb(main):001:0> require 'tk'
LoadError: cannot load such file -- tk
    from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from (irb):1
    from /usr/bin/irb:11:in `<main>'
irb(main):002:0> 

I am working on Debian-9 Linux with Ruby and Tk installed:

Package                 Installed       Previous        Now             State
=======================-===============-===============-===============-=====
tk                      8.6.0+9         8.6.0+9         8.6.0+9         install
ruby                    1:2.3.3         1:2.3.3         1:2.3.3         install

Where is the problem and how can this be solved? Thanks for your help.

Edit: As mentioned in comments, I tried to install tk with gems, but it did not work:

$ sudo gem install tk
[sudo] password for cardio: 
Fetching: tk-0.2.0.gem (100%)
Building native extensions.  This could take a while...
ERROR:  Error installing tk:
    ERROR: Failed to build gem native extension.

    current directory: /var/lib/gems/2.3.0/gems/tk-0.2.0/ext/tk
/usr/bin/ruby2.3 -r ./siteconf20170906-9548-1db359q.rb extconf.rb
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h

extconf failed, exit code 1

Gem files will remain installed in /var/lib/gems/2.3.0/gems/tk-0.2.0 for inspection.
Results logged to /var/lib/gems/2.3.0/extensions/x86-linux/2.3.0/tk-0.2.0/gem_make.out

I tried again after installing ruby-dev package (for header files), but still it failed (with a long message):

$ sudo gem install tk
Building native extensions.  This could take a while...
ERROR:  Error installing tk:
    ERROR: Failed to build gem native extension.

    current directory: /var/lib/gems/2.3.0/gems/tk-0.2.0/ext/tk
/usr/bin/ruby2.3 -r ./siteconf20170906-15971-qfma2e.rb extconf.rb
Configure options for Ruby/Tk may be updated.
So, delete files which depend on old configs.
check functions.checking for ruby_native_thread_p() in ruby.h... yes
checking for rb_errinfo() in ruby.h... yes
checking for rb_safe_level() in ruby.h... yes
checking for rb_hash_lookup() in ruby.h... yes
checking for rb_proc_new() in ruby.h... yes
checking for rb_obj_untrust() in ruby.h... yes
checking for rb_obj_taint() in ruby.h... yes
checking for rb_set_safe_level_force() in ruby.h... yes
checking for rb_sourcefile() in ruby.h... yes
checking for rb_thread_alive_p() in ruby.h... no
checking for rb_thread_check_trap_pending() in ruby.h... yes
checking for ruby_enc_find_basename() in ruby.h... yes
check libraries.checking for t_open() in -lnsl... no
checking for socket() in -lsocket... no
checking for dlopen() in -ldl... yes
checking for log() in -lm... yes
Specified Tcl/Tk version is ["8.6", "8.6"]
Use ActiveTcl libraries (if available).
Search tclConfig.sh (in /usr/lib/i386-linux-gnu/tcl8.6/tclConfig.sh) and tkConfig.sh (in /usr/lib/i386-linux-gnu/tk8.6/tkConfig.sh).
Fail to find [tclConfig.sh, tkConfig.sh]
Use X11 libraries (or use TK_XINCLUDES/TK_XLIBSW information on tkConfig.sh).
checking for XOpenDisplay() in -lX11... no
*** 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/bin/$(RUBY_BASE_NAME)2.3
    --enable-shared
    --with-tk-old-extconf
    --without-tk-old-extconf
    --with-tk-old-extconf
    --without-tk-old-extconf
    --with-ActiveTcl
    --without-ActiveTcl
    --with-tk-shlib-search-path
    --without-tk-shlib-search-path
    --with-tcltkversion
    --with-tcl-build-dir
    --without-tcl-build-dir
    --with-tk-build-dir
    --without-tk-build-dir
    --with-tcl-config
    --without-tcl-config
    --with-tk-config
    --without-tk-config
    --with-tclConfig-dir
    --with-tkConfig-dir
    --with-tclConfig-file
    --without-tclConfig-file
    --with-tkConfig-file
    --without-tkConfig-file
    --with-tcllib
    --with-tklib
    --with-tcl-dir
    --without-tcl-dir
    --with-tk-dir
    --without-tk-dir
    --with-tcl-include
    --with-tk-include
    --with-tcl-lib
    --with-tk-lib
    --with-tcltk-framework
    --without-tcltk-framework
    --with-tcl-framework-dir
    --without-tcl-framework-dir
    --with-tk-framework-dir
    --without-tk-framework-dir
    --with-tcl-framework-header
    --without-tcl-framework-header
    --with-tk-framework-header
    --without-tk-framework-header
    --with-X11
    --without-X11
    --with-X11-dir
    --without-X11-dir
    --with-X11-include
    --without-X11-include
    --with-X11-lib
    --without-X11-lib
    --enable-tcltk-stubs
    --disable-tcltk-stubs
    --enable-tcl-h-ver-check
    --disable-tcl-h-ver-check
    --enable-tk-h-ver-check
    --disable-tk-h-ver-check
    --enable-mac-tcltk-framework
    --disable-mac-tcltk-framework
    --enable-tcltk-framework
    --disable-tcltk-framework
    --enable-pthread
    --disable-pthread
    --enable-tcl-thread
    --disable-tcl-thread
    --enable-space-on-tk-libpath
    --disable-space-on-tk-libpath
    --with-nsllib
    --without-nsllib
    --with-socketlib
    --without-socketlib
    --with-dllib
    --without-dllib
    --with-mlib
    --without-mlib
    --with-tcl-build-dir
    --without-tcl-build-dir
    --with-tk-build-dir
    --without-tk-build-dir
    --with-tcltkversion
    --with-ActiveTcl
    --without-ActiveTcl
    --enable-space-on-tk-libpath
    --disable-space-on-tk-libpath
    --enable-tcltk-stubs
    --disable-tcltk-stubs
    --with-tcltk-stubs
    --without-tcltk-stubs
    --with-tcl-dir
    --without-tcl-dir
    --with-tcl-include=${tcl-dir}/include
    --with-tcl-lib=${tcl-dir}/lib
    --with-tk-dir
    --without-tk-dir
    --with-tk-include=${tk-dir}/include
    --with-tk-lib=${tk-dir}/lib
    --with-tclConfig-file
    --without-tclConfig-file
    --with-tkConfig-file
    --without-tkConfig-file
    --with-tclConfig-dir
    --with-tkConfig-dir
    --with-tk-shlib-search-path
    --without-tk-shlib-search-path
    --with-tklib
    --with-tcllib
    --with-X11
    --without-X11
    --with-X11-dir
    --without-X11-dir
    --with-X11-include
    --without-X11-include=${X11-dir}/include
    --with-X11-lib
    --without-X11-lib=${X11-dir}/lib
    --with-X11-lib
    --without-X11-lib
    --with-X11lib
    --without-X11lib

Warning:: cannot find X11 library. tcltklib will not be compiled (tcltklib is disabled on your Ruby. That is, Ruby/Tk will not work). Please check configure options. If your Tcl/Tk don't require X11, please try --without-X11.
Can't find X11 libraries. 
So, can't make tcltklib.so which is required by Ruby/Tk.

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

  /var/lib/gems/2.3.0/extensions/x86-linux/2.3.0/tk-0.2.0/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /var/lib/gems/2.3.0/gems/tk-0.2.0 for inspection.
Results logged to /var/lib/gems/2.3.0/extensions/x86-linux/2.3.0/tk-0.2.0/gem_make.out

Upvotes: 1

Views: 1698

Answers (1)

PSR
PSR

Reputation: 31

The bindings for the standard Ruby GUI toolkit, Tk, need some trickery in order to be installed on Ubuntu https://saveriomiroddi.github.io/Installing-ruby-tk-bindings-gem-on-ubuntu/

Upvotes: 3

Related Questions