I was addicted to installing Ruby/Tk on MacOS

environment

MacOS Catalina 10.15.7 Ruby 2.6.5 Tcl/Tk version 8.5 (standard)

problem

When I try to install normally as below, it fails.

$ 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:
 ~~~ Abbreviation ~~~
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

Looking at the error, it says Fail to find [tclConfig.sh, tkConfig.sh], which is very important. I couldn't find it even though I searched for it, so I'll write down the solution in the hope that it will be useful.

Until resolution

After a lot of research, it seems that you can specify the location of the Tcl/Tk library with the Configuration Option.

So, execute as follows.

$ 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:
 ~~~ Abbreviation ~~~

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

I specified the directory where the library is located, but it didn't work. .. It seems that the library cannot be found. ..

Solutions

After all, it was solved by the following.

$ 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

For --with-tcllib, enter the *** part of the tcl library file name libtcl ***. So (example: libtcl8.5.so ==> --with-tcllib = tcl8.5). .. By the way, the extension may be so or a. In my case it was libtclstub8.5.a, so I wrote it that way. Since the file name has stub, I added --enable-tcltk_stubs and forcibly enabled the stub, and I was able to install it.

After all

When I tried to implement it after installation, it failed to compile inside Ruby, so it seems that it can not be implemented with standard Tcl/Tk. After uninstalling Ruby/Tk and installing ActiveTcl8.5, I was able to implement it normally with gem install tk again. Return the time so far. .. (By the way, 8.6 didn't work)

ActiveTcl8.5 Download

Reference URL

About Configuration Option

Recommended Posts

I was addicted to installing Ruby/Tk on MacOS
I was addicted to using RXTX on Sierra
I was addicted to starting sbt
What I was addicted to while using rspec on rails
I was addicted to rewriting to @SpringApplicationConfiguration-> @SpringBootTest
I was addicted to the roll method
I was addicted to the Spring-Batch test
A note when I was addicted to converting Ubuntu on WSL1 to WSL2
I was addicted to doing onActivityResult () with DialogFragment
I was addicted to the NoSuchMethodError in Cloud Endpoints
I was addicted to the record of the associated model
A story I was addicted to when getting a key that was automatically tried on MyBatis
What I fixed when updating to Spring Boot 1.5.12 ・ What I was addicted to
I was addicted to setting default_url_options with Rails devise introduction
A story I was addicted to in Rails validation settings
I was addicted to the setting of laradock + VSCode + xdebug
What I was addicted to with the Redmine REST API
I was addicted to using Java's Stream API in Scala
The story I was addicted to when setting up STS
Android memo-I was addicted to Permission
I tried installing CentOS 8 on ESXi 6.7
[Circle CI] A story I was addicted to at Start Building
[MacOS] I was disturbed by ruby when installing Spring Boot CLI
What I was addicted to when implementing google authentication with rails
About the matter that I was addicted to how to use hashmap
I was addicted to the API version min23 setting of registerTorchCallback
Memorandum: What I was addicted to when I hit the accounting freee API
A story I was addicted to when testing the API using MockMVC
A story that I was addicted to twice with the automatic startup setting of Tomcat 8 on CentOS 8
My.cnf configuration problem that I was addicted to when I was touching MySQL 8.0 like 5.7
I was addicted to a simple test of Jedis (Java-> Redis library)
Recorded because I was addicted to the standard input of the Scanner class
I was a little addicted to running old Ruby environment and old Rails
I want to install PHP 7.2 on Ubuntu 20.04.
I was addicted to scrollview because I couldn't tap the variable size UIView
[CircleCI] I was addicted to the automatic test of CircleCI (rails + mysql) [Memo]
I was a little addicted to ssh connection from mac to linux (ubuntu)
I tried to build AdoptOpenjdk 11 on CentOS 7
I was addicted to unit testing with the buffer operator in RxJava
I was addicted to not being able to connect to AWS-S3 from the Docker container
I was a little addicted to the S3 Checksum comparison, so I made a note.
SpringSecurity I was addicted to trying to log in with a hashed password (solved)
I tried installing docker on an EC2 instance
What I was addicted to when developing a Spring Boot application with VS Code
A memo that I was addicted to when making batch processing with Spring Boot
The CSV file that I was able to download suddenly started to appear on the page.
The part I was addicted to in "Introduction to Ajax in Java Web Applications" of NetBeans
A memorandum because I was addicted to the setting of the Android project of IntelliJ IDEA
What I was addicted to when trying to properly openAPI/Swagger documentation with Rails + Grape + Grape Swagger
I want to use NetBeans on Mac → I can use it!
[Android Studio] I want to use Maven library on Android
GetXxxx of ResultSet was addicted to primitive type (Java)
What I stumbled upon when installing Ruby on Ubuntu
Things I tend to forget on MyBatis Personal summary
I want to simplify the log output on Android
A story I was addicted to before building a Ruby and Rails environment using Ubuntu (20.04.1 LTS)
[It takes 3 minutes] When I tried to install VS Code on Ubuntu 18.04, it was unexpectedly easy.
A story I was addicted to with implicit type conversion of ActiveRecord during unit testing
I was addicted to WSl when trying to build an android application development environment with Vue.js