我对Ruby非常陌生,我需要将这个库用于特定的GUI项目。我正在使用:
- Ubuntu 18.04.5 LTS
- ruby 2.5.1p57(2018-03-29修订版63029([x86_64-linux-gnu]
我的问题与此人几个月前描述的问题相似。我已经尝试了基于这篇博客文章的SO页面上发布的解决方案。
运行后:
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
这个错误消息与博客文章中描述的不同,即:
$ 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
终端返回以下错误消息:
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.
我该怎么办?
提前谢谢。
这篇博客文章解决了这个问题。
运行后:
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
一切都解决了。