无法在 Ubuntu 上加载 Ruby 的 tk

Failing to load Ruby's tk on Ubuntu

我是 Ruby 的新手,我需要将这个库用于特定的 GUI 项目。我正在使用:

我的问题类似于 this person described a few months ago. I have tried the solution posted on that SO page which is based on this 博客 post。

运行之后:

sudo apt-get install tcl8.5-dev tk8.5-dev

并且:

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.5.0/gems/tk-0.4.0/ext/tk
/usr/bin/ruby2.5 -r ./siteconf20210424-11015-1mre8d0.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.5.0/gems/tk-0.4.0 for inspection.
Results logged to /var/lib/gems/2.5.0/extensions/x86_64-linux/2.5.0/tk-0.4.0/gem_make.out

此错误消息与 blog post 中描述的错误消息不同,后者是:

$ gem install tk
Building native extensions. This could take a while...
ERROR:  Error installing tk:
  ERROR: Failed to build gem native extension.
# ...
Search tcl.h
checking for tcl.h... no
Search tk.h
checking for tk.h... no
Search Tcl library............*** extconf.rb failed ***
# ...
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).

The gem provides many switches for specifying the configuration parameters, however, the related parameters (--with-tk-lib and --with-tcl-lib) don’t yield the desired effect (actually, any effect at all).

The workaround, originally found in a Ruby forum is to symlink the libraries to the paths where the extension expects 

然后,在运行之后:

sudo ln -s /usr/lib/x86_64-linux-gnu/tcl8.5/tclConfig.sh /usr/lib/
sudo ln -s /usr/lib/x86_64-linux-gnu/tk8.5/tkConfig.sh /usr/lib/
sudo ln -s /usr/lib/x86_64-linux-gnu/libtcl8.5.so.0 /usr/lib/
sudo ln -s /usr/lib/x86_64-linux-gnu/libtk8.5.so.0 /usr/lib/

我明白了(可能是因为我之前尝试过相同的步骤):

ln: failed to create symbolic link '/usr/lib/libtk8.5.so.0': File exists

最后,运行最后一步没有工作:

sudo gem install tk

并且终端returns出现如下错误信息:

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.5.0/gems/tk-0.4.0/ext/tk
/usr/bin/ruby2.5 -r ./siteconf20210424-21301-8u83wl.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.5.0/gems/tk-0.4.0 for inspection.

我该怎么办?

提前致谢。

blog post 解决了问题。

运行之后:

sudo apt install tk-dev

并安装 Ruby/Tk gem:

gem install tk -- --with-tcltkversion=8.6 \
--with-tcl-lib=/usr/lib/x86_64-linux-gnu \
--with-tk-lib=/usr/lib/x86_64-linux-gnu \
--with-tcl-include=/usr/include/tcl8.6 \
--with-tk-include=/usr/include/tcl8.6 \
--enable-pthread

一切都解决了。