0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

MacOSでRuby/Tkのインストールでハマった

Last updated at Posted at 2020-12-20

#環境
MacOS Catalina 10.15.7
Ruby 2.6.5
Tcl/Tk version 8.5(標準搭載)

※結論は「結局」というところです。それ以外は私の奮闘記になります。

#問題
以下のように普通にインストールしようとしたら、失敗。

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

    current directory: /Users/****/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/tk-0.3.0/ext/tk
/Users/****/.rbenv/versions/2.6.5/bin/ruby -I /Users/****/.rbenv/versions/2.6.5/lib/ruby/2.6.0 -r ./siteconf20201215-2090-g0qb3m.rb extconf.rb
check functions.checking for ruby_native_thread_p() in ruby.h... yes
checking for rb_errinfo() 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_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
Use ActiveTcl libraries (if available).
Search tclConfig.sh and 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:
    ~~~略~~~
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:

  /Users/****/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/extensions/x86_64-darwin-19/2.6.0/tk-0.3.0/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /Users/****/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/tk-0.3.0 for inspection.
Results logged to /Users/****/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/extensions/x86_64-darwin-19/2.6.0/tk-0.3.0/gem_make.out

エラーを見るとFail to find [tclConfig.sh, tkConfig.sh]とあり、ここが肝っぽい。
なかなか探しても見つからなかったため、役に立てればと思い、解決法を書き記します。

#解決まで
いろいろ調べてみると、Configuration OptionでTcl/Tkライブラリの場所を指定してあげれば良いっぽい。

ということで、以下のように実行。

$ gem install tk -- --with-tcltkversion=8.5 \
--with-tcl-lib=/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Tcl.framework/Versions/8.5 \
--with-tk-lib=/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5 \

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

    current directory: /Users/****/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/tk-0.3.0/ext/tk
/Users/****/.rbenv/versions/2.6.5/bin/ruby -I /Users/****/.rbenv/versions/2.6.5/lib/ruby/2.6.0 -r ./siteconf20201215-15693-14ro7nf.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_hash_lookup() in ruby.h... yes
checking for rb_proc_new() 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.5", "8.5"]
Use ActiveTcl libraries (if available).
Search tclConfig.sh and tkConfig.sh.
Fail to find [tclConfig.sh, tkConfig.sh]
Search tcl.h
checking for tcl.h... yes
Search tk.h
checking for tk.h... yes
Search Tcl library.checking for Tcl_FindExecutable() in -ltclstub8.5... no
.checking for Tcl_FindExecutable() in -ltclstub8.5... no
.checking for Tcl_FindExecutable() in -ltclstub8.5... no
.checking for Tcl_FindExecutable() in -ltclstub8.5... 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:
    ~~~略~~~

Warning:: cannot find Tcl library. tcltklib will not be compiled (tcltklib is disabled on your Ruby. That is, Ruby/Tk will not work). Please check configure options.

Can't find proper Tcl/Tk libraries. So, can't make tcltklib.so which is required by Ruby/Tk.
If you have Tcl/Tk libraries on your environment, you may be able to use them with configure options (see ext/tk/README.tcltklib).
At present, Tcl/Tk8.6 is not supported. Although you can try to use Tcl/Tk8.6 with configure options, it will not work correctly. I recommend you to use Tcl/Tk8.5 or 8.4.

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

  /Users/****/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/extensions/x86_64-darwin-19/2.6.0/tk-0.3.0/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /Users/****/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/tk-0.3.0 for inspection.
Results logged to /Users/****/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/extensions/x86_64-darwin-19/2.6.0/tk-0.3.0/gem_make.out

ライブラリのあるディレクトリを指定したのにダメでした。。
ライブラリが見つからないらしい。。

#解決方法
結局以下で解決しました。

$ gem install tk -- --with-tcltkversion=8.5 \
--with-tcllib=tclstub8.5 \
--with-tklib=tkstub8.5 \
--enable-tcltk_stubs

Building native extensions with: '--with-tcltkversion=8.5 --with-tcllib=tclstub8.5 --with-tklib=tkstub8.5 --enable-tcltk_stubs'
This could take a while...
Successfully installed tk-0.3.0
Parsing documentation for tk-0.3.0
Installing ri documentation for tk-0.3.0
Done installing documentation for tk after 8 seconds
1 gem installed

--with-tcllibはtclライブラリのファイル名libtcl***.soの***の部分を記入(例:libtcl8.5.so ==> --with-tcllib = tcl8.5)。
ちなみに拡張子はsoの場合もあれば、aの場合もあります。
自分の場合はlibtclstub8.5.aだったので、そのように書きました。
ファイル名にstubがついてたので、--enable-tcltk_stubsをつけて強制的にスタブを有効にしたら、インストールできました。

#結局
インストール後に実装しようと思ったらRuby内部でコンパイルに失敗したので、おそらく、標準のTcl/Tkでは実装できないっぽいです。一度、Ruby/Tkをアンインストール後、ActiveTcl8.5をインストールしたのち、再度gem install tkで普通に実装できました。今までの時間返して。。
(ちなみに8.6ではだめでした)

ActiveTcl8.5 Download

#参考URL
Configuration Optionについて

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?