前提・実現したいこと
MacのRubyで、GTK2やGTK3を導入することが目標です。
HomebrewでGTK+、GTK+3をインストールし、gemで、gtk2、gtk3をインストールしました。
そして下記のような入門用の簡単なgtk2のサンプルコードを試しに実行しましたが、「require'gtk2'」の時点でロードにエラーが発生してしまいます。
コード
Ruby
1require 'gtk2' 2 3window = Gtk::Window.new 4window.show 5Gtk.main
エラーメッセージ
(null)-WARNING **: Failed to load shared library 'libatk-1.0.0.dylib' referenced by the typelib: dlopen(libatk-1.0.0.dylib, 0x0009): relative file paths not allowed 'libatk-1.0.0.dylib' from /Library/Ruby/Gems/2.6.0/gems/gobject-introspection-3.4.1/lib/gobject-introspection/loader.rb:544:in `load_interface_info' from /Library/Ruby/Gems/2.6.0/gems/gobject-introspection-3.4.1/lib/gobject-introspection/loader.rb:70:in `load_info' from /Library/Ruby/Gems/2.6.0/gems/gobject-introspection-3.4.1/lib/gobject-introspection/loader.rb:40:in `block in load' from /Library/Ruby/Gems/2.6.0/gems/gobject-introspection-3.4.1/lib/gobject-introspection/repository.rb:34:in `block (2 levels) in each' from /Library/Ruby/Gems/2.6.0/gems/gobject-introspection-3.4.1/lib/gobject-introspection/repository.rb:33:in `times' from /Library/Ruby/Gems/2.6.0/gems/gobject-introspection-3.4.1/lib/gobject-introspection/repository.rb:33:in `block in each' from /Library/Ruby/Gems/2.6.0/gems/gobject-introspection-3.4.1/lib/gobject-introspection/repository.rb:32:in `each' from /Library/Ruby/Gems/2.6.0/gems/gobject-introspection-3.4.1/lib/gobject-introspection/repository.rb:32:in `each' from /Library/Ruby/Gems/2.6.0/gems/gobject-introspection-3.4.1/lib/gobject-introspection/loader.rb:39:in `load' from /Library/Ruby/Gems/2.6.0/gems/atk-3.4.1/lib/atk.rb:27:in `<module:Atk>' from /Library/Ruby/Gems/2.6.0/gems/atk-3.4.1/lib/atk.rb:19:in `<top (required)>' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require' from /Library/Ruby/Gems/2.6.0/gems/gtk2-3.4.1/lib/gtk2/base.rb:13:in `<top (required)>' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require' from /Library/Ruby/Gems/2.6.0/gems/gtk2-3.4.1/lib/gtk2.rb:11:in `<top (required)>' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:130:in `require' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:130:in `rescue in require' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:34:in `require' from gtk.rb:1:in `<main>' (null)-WARNING **: Failed to load shared library 'libpango-1.0.0.dylib' referenced by the typelib: dlopen(libpango-1.0.0.dylib, 0x0009): relative file paths not allowed 'libpango-1.0.0.dylib' from /Library/Ruby/Gems/2.6.0/gems/gobject-introspection-3.4.1/lib/gobject-introspection/loader.rb:179:in `load_enum_info' from /Library/Ruby/Gems/2.6.0/gems/gobject-introspection-3.4.1/lib/gobject-introspection/loader.rb:66:in `load_info' from /Library/Ruby/Gems/2.6.0/gems/gobject-introspection-3.4.1/lib/gobject-introspection/loader.rb:43:in `block in load' from /Library/Ruby/Gems/2.6.0/gems/gobject-introspection-3.4.1/lib/gobject-introspection/repository.rb:34:in `block (2 levels) in each' from /Library/Ruby/Gems/2.6.0/gems/gobject-introspection-3.4.1/lib/gobject-introspection/repository.rb:33:in `times' from /Library/Ruby/Gems/2.6.0/gems/gobject-introspection-3.4.1/lib/gobject-introspection/repository.rb:33:in `block in each' from /Library/Ruby/Gems/2.6.0/gems/gobject-introspection-3.4.1/lib/gobject-introspection/repository.rb:32:in `each' from /Library/Ruby/Gems/2.6.0/gems/gobject-introspection-3.4.1/lib/gobject-introspection/repository.rb:32:in `each' from /Library/Ruby/Gems/2.6.0/gems/gobject-introspection-3.4.1/lib/gobject-introspection/loader.rb:42:in `load' from /Library/Ruby/Gems/2.6.0/gems/pango-3.4.1/lib/pango.rb:29:in `<module:Pango>' from /Library/Ruby/Gems/2.6.0/gems/pango-3.4.1/lib/pango.rb:24:in `<top (required)>' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require' from /Library/Ruby/Gems/2.6.0/gems/gtk2-3.4.1/lib/gtk2/base.rb:14:in `<top (required)>' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require' from /Library/Ruby/Gems/2.6.0/gems/gtk2-3.4.1/lib/gtk2.rb:11:in `<top (required)>' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:130:in `require' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:130:in `rescue in require' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:34:in `require' from gtk.rb:1:in `<main>' Traceback (most recent call last): 2: from gtk.rb:1:in `<main>' 1: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require' /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- gtk2 (LoadError) 18: from gtk.rb:1:in `<main>' 17: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:34:in `require' 16: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:130:in `rescue in require' 15: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:130:in `require' 14: from /Library/Ruby/Gems/2.6.0/gems/gtk2-3.4.1/lib/gtk2.rb:11:in `<top (required)>' 13: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require' 12: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require' 11: from /Library/Ruby/Gems/2.6.0/gems/gtk2-3.4.1/lib/gtk2/base.rb:14:in `<top (required)>' 10: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require' 9: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require' 8: from /Library/Ruby/Gems/2.6.0/gems/pango-3.4.1/lib/pango.rb:24:in `<top (required)>' 7: from /Library/Ruby/Gems/2.6.0/gems/pango-3.4.1/lib/pango.rb:29:in `<module:Pango>' 6: from /Library/Ruby/Gems/2.6.0/gems/gobject-introspection-3.4.1/lib/gobject-introspection/loader.rb:45:in `load' 5: from /Library/Ruby/Gems/2.6.0/gems/pango-3.4.1/lib/pango/loader.rb:32:in `post_load' 4: from /Library/Ruby/Gems/2.6.0/gems/pango-3.4.1/lib/pango/loader.rb:85:in `require_libraries' 3: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require' 2: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require' 1: from /Library/Ruby/Gems/2.6.0/gems/pango-3.4.1/lib/pango/attr-type.rb:17:in `<top (required)>' /Library/Ruby/Gems/2.6.0/gems/pango-3.4.1/lib/pango/attr-type.rb:18:in `<module:Pango>': AttrType is not a class (TypeError)
試したこと
エラーについて色々調べたのですが、そもそもRuby、GTKなどに関する知識が浅く、「gobject-introspection」が原因なのか、「pango」や、「atk」、「GTK+」あるいは「gem」自体が原因なのかなどもあまり理解できませんでした。
ただ、以前にgemでインストールしたnokogiriをrequireして、用いたことはあり、そのときは問題なかったので、おそらくgemやそのパスの問題ではないと思っています。
また、そもそもGTK+がちゃんと入っているのか気になったので、このサイトを参考に、c言語でのサンプルを動かしましたがこれは動作しました。なのでbrewでインストールしたGTK側の問題でもないように思います。
ちょっとどこに手をつければいいのかわからないので、「ここがおかしいんじゃないか」とか何かアドバイスあれば教えてください。
お手数ですがよろしくお願いします。
補足情報(FW/ツールのバージョンなど)
OS:MacOS Catalina
GTK+はbrewでインストールしました。
今回たまたま、RubyでGtkを使ったunix向けソフトを動かしたかったためなんとか導入しようとしましたが、正直、Ruby、GTKについては恥ずかしながらほとんど存じておりません。
gemlist
1*** LOCAL GEMS *** 2 3actioncable (6.0.1) 4--中略-- 5atk (3.4.1) 6bigdecimal (default: 1.4.1) 7builder (3.2.3) 8bundler (default: 1.17.2) 9cairo (1.16.4) 10cairo-gobject (3.4.1) 11--中略-- 12gdk3 (3.4.1) 13gdk_pixbuf2 (3.4.1) 14gettext (3.2.9) 15gio2 (3.4.1) 16glib2 (3.4.1) 17globalid (0.4.2) 18gobject-introspection (3.4.1) 19gtk2 (3.4.1) 20gtk3 (3.4.1) 21--中略-- 22pango (3.4.1) 23--中略-- 24rake (13.0.1, 12.3.2) 25--以下略--
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。