mieki256's diary



2023/10/19(木) [n年前の日記]

#1 [ruby] Ruby/GTK3を使ってるスクリプトをexe化したかったけどできなかった

Windows10 x64 22H2上で、gtk3 (Ruby/GTK3, ruby-gtk3) を使っているRubyスクリプトをexe化できるのか気になったので試してみた。

結論を先に書くと、gtk3 を使ったRubyスクリプトは、exe化できなかった。ちなみに、FXRuby や LibUI を使ったRubyスクリプトならexe化できた。

RubyバージョンGUIライブラリ日本語入力画像表示exe化exe化ツール
Ruby 2.6.10 x86LibUI 0.0.15YesNoYesocra 1.3.11
Ruby 3.2.2 x86LibUI 0.0.15YesNoYesocran 1.3.14
Ruby 2.6.10 x86FXRuby 1.6.46 x86-mingw32NoYesYesocra 1.3.11
Ruby 3.2.2 x86FXRuby 1.6.46 x86-mingw32NoYesYesocran 1.3.14
Ruby 2.6.10 x86gtk3 4.2.0YesYesNoocra 1.3.11
Ruby 3.2.2 x86gtk3 4.2.0YesYesNoocran 1.3.14

「Windows上でRubyを使ってGUIアプリを作りたいなら ruby-gtk3 一択かもしれない」と書いてしまったけれど、それは間違いだった模様。exe化できないのではなあ…。

_GitHub - kojix2/LibUI: A portable GUI library for Ruby
_libui | RubyGems.org | コミュニティのgemホスティングサービス

_GitHub - larskanis/fxruby: FXRuby is an extension module for Ruby that provides an interface to the FOX GUI toolkit.
_fxruby | RubyGems.org | コミュニティのgemホスティングサービス

_gtk3 | RubyGems.org | コミュニティのgemホスティングサービス
_The source of https://ruby-gnome.github.io/ | ruby-gnome.github.io

Ruby 3.2.2 x86 の場合 :

Ruby 3.2.2 x86 (RubyInstaller2) を使って試してみた。ocra を使えばexe化できるかなと思ったけれど…。
> ruby --version
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [i386-mingw32]

> ocra 08_image2.rb
=== Loading script to check dependencies
=== Attempting to trigger autoload of Matrix::EigenvalueDecomposition
=== Attempting to trigger autoload of Matrix::LUPDecomposition
=== Detected gem error_highlight-0.5.1 (loaded, files)
===     0 files, 0 bytes
=== Detected gem did_you_mean-1.6.3 (loaded, files)
===     0 files, 0 bytes
=== Detected gem syntax_suggest-1.0.2 (loaded, files)
===     0 files, 0 bytes
=== Detected gem ocra-1.3.11 (loaded, files)
===     5 files, 271800 bytes
=== Detected gem pkg-config-1.5.5 (loaded, files)
===     3 files, 34908 bytes
=== Detected gem native-package-installer-1.1.8 (loaded, files)
===     0 files, 0 bytes
=== Detected gem glib2-4.2.0 (loaded, files)
===     21 files, 858833 bytes
=== Detected gem atk-4.2.0 (loaded, files)
===     5 files, 31420 bytes
=== Detected gem matrix-0.4.2 (loaded, files)
===     4 files, 92057 bytes
=== Detected gem red-colors-0.3.0 (loaded, files)
===     44 files, 295060 bytes
=== Detected gem cairo-1.17.12 (loaded, files)
===     27 files, 759830 bytes
=== Detected gem cairo-gobject-4.2.0 (loaded, files)
===     6 files, 76283 bytes
=== Detected gem gobject-introspection-4.2.0 (loaded, files)
===     22 files, 360545 bytes
=== Detected gem pango-4.2.0 (loaded, files)
===     24 files, 119909 bytes
=== Detected gem fiddle-1.1.1 (loaded, files)
===     0 files, 0 bytes
=== Detected gem gio2-4.2.0 (loaded, files)
===     28 files, 111052 bytes
=== Detected gem gdk_pixbuf2-4.2.0 (loaded, files)
===     12 files, 63139 bytes
=== Detected gem gdk3-4.2.0 (loaded, files)
===     19 files, 73561 bytes
=== Detected gem gtk3-4.2.0 (loaded, files)
===     254 files, 1427401 bytes
=== Detected gem pathname-0.2.1 (loaded, files)
===     0 files, 0 bytes
=== Detected gem english-0.7.2 (loaded, files)
===     0 files, 0 bytes
=== Detected gem date-3.3.3 (loaded, files)
===     0 files, 0 bytes
=== Detected gem time-0.2.2 (loaded, files)
===     0 files, 0 bytes
=== Detected gem json-2.6.3 (loaded, files)
===     0 files, 0 bytes
=== Detected gem ostruct-0.5.5 (loaded, files)
===     0 files, 0 bytes
=== Detected gem forwardable-1.3.3 (loaded, files)
===     0 files, 0 bytes
=== Including 61 encoding support files (3706880 bytes, use --no-enc to exclude)
=== Building 08_image2.exe
=== Adding user-supplied source files
D:/Ruby/Ruby32-x86/lib/ruby/gems/3.2.0/gems/ocra-1.3.11/bin/ocra:1188:in `initialize': No such file or directory @ rb_sysopen - D:/home/prg/ruby/_work_sample/gtk3/fiber.so (Errno::ENOENT)
        from D:/Ruby/Ruby32-x86/lib/ruby/gems/3.2.0/gems/ocra-1.3.11/bin/ocra:1188:in `open'
        from D:/Ruby/Ruby32-x86/lib/ruby/gems/3.2.0/gems/ocra-1.3.11/bin/ocra:1188:in `createfile'
        from D:/Ruby/Ruby32-x86/lib/ruby/gems/3.2.0/gems/ocra-1.3.11/bin/ocra:898:in `block (2 levels) in build_exe'
        from D:/Ruby/Ruby32-x86/lib/ruby/gems/3.2.0/gems/ocra-1.3.11/bin/ocra:882:in `each'
        from D:/Ruby/Ruby32-x86/lib/ruby/gems/3.2.0/gems/ocra-1.3.11/bin/ocra:882:in `block in build_exe'
        from D:/Ruby/Ruby32-x86/lib/ruby/gems/3.2.0/gems/ocra-1.3.11/bin/ocra:1087:in `block in initialize'
        from D:/Ruby/Ruby32-x86/lib/ruby/gems/3.2.0/gems/ocra-1.3.11/bin/ocra:1071:in `open'
        from D:/Ruby/Ruby32-x86/lib/ruby/gems/3.2.0/gems/ocra-1.3.11/bin/ocra:1071:in `initialize'
        from D:/Ruby/Ruby32-x86/lib/ruby/gems/3.2.0/gems/ocra-1.3.11/bin/ocra:879:in `new'
        from D:/Ruby/Ruby32-x86/lib/ruby/gems/3.2.0/gems/ocra-1.3.11/bin/ocra:879:in `build_exe'
        from D:/Ruby/Ruby32-x86/lib/ruby/gems/3.2.0/gems/ocra-1.3.11/bin/ocra:1231:in `block in <top (required)>'

エラーが出てしまった。fiber.so が見つからないと言っているのだろうか。fiber って何だろう。"ruby fiber" でググってみたら組み込みライブラリと出てきたけど…。

Ruby 2.6.10 x86 の場合 :

Ruby 2.6.10 x86 で試してみた。これも ocra でexe化できないか試した。
> ruby --version
ruby 2.6.10p210 (2022-04-12 revision 67958) [i386-mingw32]

> ocra 08_image2.rb images
=== Loading script to check dependencies
=== Attempting to trigger autoload of Matrix::EigenvalueDecomposition
=== Attempting to trigger autoload of Matrix::LUPDecomposition
=== Detected gem did_you_mean-1.5.0 (loaded, files)
===     25 files, 31813 bytes
=== Detected gem ocra-1.3.11 (loaded, files)
===     5 files, 271800 bytes
=== Detected gem pkg-config-1.5.5 (loaded, files)
===     3 files, 34908 bytes
=== Detected gem native-package-installer-1.1.5 (loaded, files)
===     0 files, 0 bytes
=== Detected gem glib2-4.2.0 (loaded, files)
===     21 files, 887505 bytes
=== Detected gem atk-4.2.0 (loaded, files)
===     5 files, 31420 bytes
=== Detected gem red-colors-0.3.0 (loaded, files)
===     44 files, 295060 bytes
=== Detected gem cairo-1.17.12 (loaded, files)
===     27 files, 759830 bytes
=== Detected gem cairo-gobject-4.2.0 (loaded, files)
===     6 files, 75259 bytes
=== Detected gem gobject-introspection-4.2.0 (loaded, files)
===     22 files, 361569 bytes
=== Detected gem pango-4.2.0 (loaded, files)
===     24 files, 117861 bytes
=== Detected gem gio2-4.2.0 (loaded, files)
===     28 files, 109004 bytes
=== Detected gem gdk_pixbuf2-4.2.0 (loaded, files)
===     12 files, 63139 bytes
=== Detected gem gdk3-4.2.0 (loaded, files)
===     19 files, 73561 bytes
=== Detected gem gtk3-4.2.0 (loaded, files)
===     254 files, 1428425 bytes
=== Detected gem date-3.1.1 (loaded, files)
===     4 files, 481268 bytes
=== Detected gem matrix-0.4.2 (loaded, files)
===     5 files, 92981 bytes
=== Detected gem json-2.5.1 (loaded, files)
===     14 files, 208760 bytes
=== Detected gem ostruct-0.4.0 (loaded, files)
===     6 files, 15432 bytes
=== Detected gem forwardable-1.3.2 (loaded, files)
===     3 files, 10555 bytes
=== Detected gem fiddle-1.0.9 (loaded, files)
===     8 files, 165712 bytes
=== Including 59 encoding support files (3672064 bytes, use --no-enc to exclude)
=== Building 08_image2.exe
=== Adding user-supplied source files
=== Adding ruby executable ruby.exe
=== Adding detected DLL D:/Ruby/Ruby26-x86/bin/ruby_builtin_dlls/libssp-0.dll
=== Adding detected DLL D:/Ruby/Ruby26-x86/bin/ruby_builtin_dlls/libgmp-10.dll
=== Adding detected DLL D:/Ruby/Ruby26-x86/bin/ruby_builtin_dlls/libgcc_s_dw2-1.dll
=== Adding detected DLL D:/Ruby/Ruby26-x86/bin/ruby_builtin_dlls/libwinpthread-1.dll
=== Adding detected DLL D:/Ruby/Ruby26-x86/bin/ruby_builtin_dlls/libintl-8.dll
=== Adding detected DLL D:/Ruby/Ruby26-x86/msys32/mingw32/bin/libgobject-2.0-0.dll
=== Adding detected DLL D:/Ruby/Ruby26-x86/bin/ruby_builtin_dlls/libiconv-2.dll
=== Adding detected DLL D:/Ruby/Ruby26-x86/msys32/mingw32/bin/libglib-2.0-0.dll
=== Adding detected DLL D:/Ruby/Ruby26-x86/bin/ruby_builtin_dlls/libffi-7.dll
=== Adding detected DLL D:/Ruby/Ruby26-x86/msys32/mingw32/bin/libpcre-1.dll
=== Adding detected DLL D:/Ruby/Ruby26-x86/msys32/mingw32/bin/libgirepository-1.0-1.dll
=== Adding detected DLL D:/Ruby/Ruby26-x86/msys32/mingw32/bin/libgmodule-2.0-0.dll
=== Adding detected DLL D:/Ruby/Ruby26-x86/msys32/mingw32/bin/libgio-2.0-0.dll
=== Adding detected DLL D:/Ruby/Ruby26-x86/bin/ruby_builtin_dlls/zlib1.dll
=== Adding detected DLL D:/Ruby/Ruby26-x86/msys32/mingw32/bin/libatk-1.0-0.dll
=== Adding detected DLL D:/Ruby/Ruby26-x86/msys32/mingw32/bin/libfreetype-6.dll
=== Adding detected DLL D:/Ruby/Ruby26-x86/msys32/mingw32/bin/libcairo-2.dll
=== Adding detected DLL D:/Ruby/Ruby26-x86/msys32/mingw32/bin/libbz2-1.dll
=== Adding detected DLL D:/Ruby/Ruby26-x86/msys32/mingw32/bin/libbrotlidec.dll
=== Adding detected DLL D:/Ruby/Ruby26-x86/msys32/mingw32/bin/libharfbuzz-0.dll
=== Adding detected DLL D:/Ruby/Ruby26-x86/msys32/mingw32/bin/libpng16-16.dll
=== Adding detected DLL D:/Ruby/Ruby26-x86/msys32/mingw32/bin/libstdc++-6.dll
=== Adding detected DLL D:/Ruby/Ruby26-x86/msys32/mingw32/bin/libfontconfig-1.dll
=== Adding detected DLL D:/Ruby/Ruby26-x86/msys32/mingw32/bin/libpixman-1-0.dll
=== Adding detected DLL D:/Ruby/Ruby26-x86/msys32/mingw32/bin/libbrotlicommon.dll
=== Adding detected DLL D:/Ruby/Ruby26-x86/msys32/mingw32/bin/libgraphite2.dll
=== Adding detected DLL D:/Ruby/Ruby26-x86/msys32/mingw32/bin/libexpat-1.dll
=== Adding detected DLL D:/Ruby/Ruby26-x86/msys32/mingw32/bin/libcairo-gobject-2.dll
=== Adding detected DLL D:/Ruby/Ruby26-x86/msys32/mingw32/bin/libpango-1.0-0.dll
=== Adding detected DLL D:/Ruby/Ruby26-x86/msys32/mingw32/bin/libthai-0.dll
=== Adding detected DLL D:/Ruby/Ruby26-x86/msys32/mingw32/bin/libfribidi-0.dll
=== Adding detected DLL D:/Ruby/Ruby26-x86/msys32/mingw32/bin/libdatrie-1.dll
=== Adding detected DLL D:/Ruby/Ruby26-x86/msys32/mingw32/bin/libpangocairo-1.0-0.dll
=== Adding detected DLL D:/Ruby/Ruby26-x86/msys32/mingw32/bin/libpangoft2-1.0-0.dll
=== Adding detected DLL D:/Ruby/Ruby26-x86/msys32/mingw32/bin/libpangowin32-1.0-0.dll
=== Adding detected DLL D:/Ruby/Ruby26-x86/msys32/mingw32/bin/libgdk_pixbuf-2.0-0.dll
=== Adding detected DLL D:/Ruby/Ruby26-x86/msys32/mingw32/bin/libgdk-3-0.dll
=== Adding detected DLL D:/Ruby/Ruby26-x86/msys32/mingw32/bin/libepoxy-0.dll
=== Adding detected DLL D:/Ruby/Ruby26-x86/msys32/mingw32/bin/libgtk-3-0.dll
=== Adding detected DLL D:/Ruby/Ruby26-x86/msys32/mingw32/lib/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-png.dll
=== Adding external manifest D:/Ruby/Ruby26-x86/bin/ruby_builtin_dlls/ruby_builtin_dlls.manifest
=== Adding external manifest D:/Ruby/Ruby26-x86/msys32/mingw32/bin/mako-render.exe.manifest
=== Adding external manifest D:/Ruby/Ruby26-x86/msys32/mingw32/bin/update-mime-database.exe.manifest
=== Adding library files
=== Compressing 41277968 bytes

LZMA 19.00 (x86) : Igor Pavlov : Public domain : 2019-02-21

Input size:  41277968 (39 MiB)
Output size: 10519402 (10 MiB)
=== Finished building 08_image2.exe (10570110 bytes)

一見すると exe が作れたように見えたけれど、実行してみると動作しない。
> 08_image2.exe
C:/Users/(USERNAME)/AppData/Local/Temp/ocrA5C9.tmp/lib/ruby/site_ruby/2.6.0/rubygems/core_ext/kernel_require.rb:85:in `require': 126: 指定されたモジュールが見つかりません。   - C:/Users/(USERNAME)/AppData/Local/Temp/ocrA5C9.tmp/lib/ruby/gems/2.6.0/gems/gobject-int
rospection-4.2.0/lib/gobject_introspection.so (LoadError)
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocrA5C9.tmp/lib/ruby/site_ruby/2.6.0/rubygems/core_ext/kernel_require.rb:85:in `require'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocrA5C9.tmp/lib/ruby/gems/2.6.0/gems/gobject-introspection-4.2.0/lib/gobject-introspection.rb:34:in `<top (required)>'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocrA5C9.tmp/lib/ruby/site_ruby/2.6.0/rubygems/core_ext/kernel_require.rb:85:in `require'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocrA5C9.tmp/lib/ruby/site_ruby/2.6.0/rubygems/core_ext/kernel_require.rb:85:in `require'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocrA5C9.tmp/lib/ruby/gems/2.6.0/gems/atk-4.2.0/lib/atk.rb:17:in `<top (required)>'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocrA5C9.tmp/lib/ruby/site_ruby/2.6.0/rubygems/core_ext/kernel_require.rb:85:in `require'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocrA5C9.tmp/lib/ruby/site_ruby/2.6.0/rubygems/core_ext/kernel_require.rb:85:in `require'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocrA5C9.tmp/lib/ruby/gems/2.6.0/gems/gtk3-4.2.0/lib/gtk3.rb:17:in `<top (required)>'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocrA5C9.tmp/lib/ruby/site_ruby/2.6.0/rubygems/core_ext/kernel_require.rb:160:in `require'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocrA5C9.tmp/lib/ruby/site_ruby/2.6.0/rubygems/core_ext/kernel_require.rb:160:in `rescue in require'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocrA5C9.tmp/lib/ruby/site_ruby/2.6.0/rubygems/core_ext/kernel_require.rb:149:in `require'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocrA5C9.tmp/src/08_image2.rb:14:in `<main>'
C:/Users/(USERNAME)/AppData/Local/Temp/ocrA5C9.tmp/lib/ruby/site_ruby/2.6.0/rubygems/core_ext/kernel_require.rb:85:in `require': cannot load such file -- gtk3 (LoadError)
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocrA5C9.tmp/lib/ruby/site_ruby/2.6.0/rubygems/core_ext/kernel_require.rb:85:in `require'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocrA5C9.tmp/src/08_image2.rb:14:in `<main>'

gobject_introspection.so が見つからないし、gtk3 もロードできないと言っているように見える。

Ruby 3.0.4 x86 の場合 :

Ruby 3.0.4 x86 + ocra で試してみた。

.exe は作成できたけど、実行してみるとエラーになった。エラーメッセージの量からすると、Ruby 2.6.10 x86 より酷い状態になった…。
> 08_image2.exe
C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/specification.rb:1406:in `rescue in block in activate_dependencies': Could not find 'pkg-config' (>= 1.3.5) among 23 total gem(s) (Gem::MissingSpecError)
Checked in 'GEM_PATH=C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/gemhome;C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/gems/3.0.0' at: C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/gems/3.0.0/specifications/glib2-4.2.0.gemspec, execute `gem env` for more information
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/specification.rb:1403:in `block in activate_dependencies'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/specification.rb:1392:in `each'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/specification.rb:1392:in `activate_dependencies'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/specification.rb:1374:in `activate'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/specification.rb:1410:in `block in activate_dependencies'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/specification.rb:1392:in `each'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/specification.rb:1392:in `activate_dependencies'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/specification.rb:1374:in `activate'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/specification.rb:1410:in `block in activate_dependencies'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/specification.rb:1392:in `each'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/specification.rb:1392:in `activate_dependencies'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/specification.rb:1374:in `activate'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems.rb:221:in `rescue in try_activate'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems.rb:214:in `try_activate'
        from <internal:C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:153:in `rescue in require'
        from <internal:C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:149:in `require'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/src/08_image2.rb:14:in `<main>'
C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/dependency.rb:311:in `to_specs': Could not find 'pkg-config' (>= 1.3.5) among 23 total gem(s) (Gem::MissingSpecError)
Checked in 'GEM_PATH=C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/gemhome;C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/gems/3.0.0' , execute `gem env` for more information
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/specification.rb:1404:in `block in activate_dependencies'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/specification.rb:1392:in `each'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/specification.rb:1392:in `activate_dependencies'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/specification.rb:1374:in `activate'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/specification.rb:1410:in `block in activate_dependencies'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/specification.rb:1392:in `each'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/specification.rb:1392:in `activate_dependencies'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/specification.rb:1374:in `activate'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/specification.rb:1410:in `block in activate_dependencies'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/specification.rb:1392:in `each'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/specification.rb:1392:in `activate_dependencies'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/specification.rb:1374:in `activate'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems.rb:221:in `rescue in try_activate'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems.rb:214:in `try_activate'
        from <internal:C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:153:in `rescue in require'
        from <internal:C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:149:in `require'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/src/08_image2.rb:14:in `<main>'
C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/specification.rb:1406:in `rescue in block in activate_dependencies': Could not find 'pkg-config' (>= 1.3.5) among 23 total gem(s) (Gem::MissingSpecError)
Checked in 'GEM_PATH=C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/gemhome;C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/gems/3.0.0' at: C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/gems/3.0.0/specifications/glib2-4.2.0.gemspec, execute `gem env` for more information
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/specification.rb:1403:in `block in activate_dependencies'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/specification.rb:1392:in `each'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/specification.rb:1392:in `activate_dependencies'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/specification.rb:1374:in `activate'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/specification.rb:1410:in `block in activate_dependencies'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/specification.rb:1392:in `each'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/specification.rb:1392:in `activate_dependencies'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/specification.rb:1374:in `activate'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/specification.rb:1410:in `block in activate_dependencies'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/specification.rb:1392:in `each'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/specification.rb:1392:in `activate_dependencies'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/specification.rb:1374:in `activate'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems.rb:215:in `try_activate'
        from <internal:C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:153:in `rescue in require'
        from <internal:C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:149:in `require'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/src/08_image2.rb:14:in `<main>'
C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/dependency.rb:311:in `to_specs': Could not find 'pkg-config' (>= 1.3.5) among 23 total gem(s) (Gem::MissingSpecError)
Checked in 'GEM_PATH=C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/gemhome;C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/gems/3.0.0' , execute `gem env` for more information
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/specification.rb:1404:in `block in activate_dependencies'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/specification.rb:1392:in `each'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/specification.rb:1392:in `activate_dependencies'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/specification.rb:1374:in `activate'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/specification.rb:1410:in `block in activate_dependencies'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/specification.rb:1392:in `each'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/specification.rb:1392:in `activate_dependencies'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/specification.rb:1374:in `activate'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/specification.rb:1410:in `block in activate_dependencies'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/specification.rb:1392:in `each'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/specification.rb:1392:in `activate_dependencies'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/specification.rb:1374:in `activate'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems.rb:215:in `try_activate'
        from <internal:C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:153:in `rescue in require'
        from <internal:C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:149:in `require'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/src/08_image2.rb:14:in `<main>'
<internal:C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require': cannot load such file -- gtk3 (LoadError)
        from <internal:C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocr5D57.tmp/src/08_image2.rb:14:in `<main>'

ocraのバグらしい :

fiber.so が見つからないと言ってくる件は、Ruby 3.1 以降の仕様変更によるもので、ocra が対応できてない状態らしい。

_Ruby 3.1 doesn't bring fiber.so and crashes Ocra - Issue #179 - larsch/ocra - GitHub
_Possible error: No such file or directory @ rb_sysopen - C:/home/x/programming/ruby/src/roebe/bin/fiber.so (Errno::ENOENT) - Issue #186 - larsch/ocra - GitHub


パッチはあるらしいけど反映されてないっぽい。

_Ignore fiber.so by sk757a - Pull Request #189 - larsch/ocra - GitHub


上記の修正を、Ruby 3.2.2 x86 にインストールした ocra に対してやってみた。以下のファイルを修正する。
(Ruby 3.2.2 x86インストールフォルダ)\lib\ruby\gems\3.2.0\gems\ocra-1.3.11\bin\ocra

fiber.so 云々のエラーは出なくなって exe も生成できるようになった。しかし、出来上がった exe を実行するとエラーになる。
> 08_image2.exe
C:/Users/(USERNAME)/AppData/Local/Temp/ocrDFB4.tmp/lib/ruby/site_ruby/3.2.0/rubygems.rb:1366:in `read': No such file or directory @ rb_sysopen - C:/Users/(USERNAME)/AppData/Local/Temp/ocrDFB4.tmp/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb (Errno::ENOENT)
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocrDFB4.tmp/lib/ruby/site_ruby/3.2.0/rubygems.rb:1366:in `<top (required)>'
        from <internal:gem_prelude>:2:in `require'
        from <internal:gem_prelude>:2:in `<internal:gem_prelude>'

ruby-gtk3以外で試してみた :

ruby-gtk3 で試してるからいかんのだろうか。別のGUIライブラリならどうなるのだろう。

まず、Ruby 2.6.10 x86 + ocra 1.3.11 を使って試してみる。
  • libui 0.0.15 を使ってるRubyスクリプトは、exe も生成できたし、exe を実行することもできた。
  • fxruby 1.6.46 x86-mingw32 を使ってるRubyスクリプトも、exe を生成できたし、exe を実行することもできた。

次に、Ruby 3.2.2 x86 + ocra 1.3.11 を使って試してみた。尚、ocra は、fiber.so を除外するように修正した版を使用。

libui 0.0.15 を使ってるRubyスクリプトをexe化してみた。exe は生成できたけど、実行するとエラーになる。
> 01_hello_libui.exe
C:/Users/(USERNAME)/AppData/Local/Temp/ocr92BE.tmp/lib/ruby/site_ruby/3.2.0/rubygems.rb:1366:in `read': No such file or directory @ rb_sysopen - C:/Users/(USERNAME)/AppData/Local/Temp/ocr92BE.tmp/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb (Errno::ENOENT)
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocr92BE.tmp/lib/ruby/site_ruby/3.2.0/rubygems.rb:1366:in `<top (required)>'
        from <internal:gem_prelude>:2:in `require'
        from <internal:gem_prelude>:2:in `<internal:gem_prelude>'

gtk3 ではなく、LibUI を使っているにも関わらず、gtk3 を利用したスクリプトをexe化した場合と同じエラーが出ているように見える。

どうやら、「ocra は Ruby 3.x 以降に対応していない」と思っておいたほうがいいのかもしれない。

ocraのfork版のocranを導入してみる :

Ruby 3.x 以降で ocra が使えない問題は、一応、issue で報告済みではある模様。放置されてるようにも見えるけど…。

_Executable created with Ocra and Ruby 3.2.2 throw an error - Issue #193 - larsch/ocra - GitHub

そして、この報告に関するやり取りの中で、このあたりのバグを修正した、ocran というfork版が存在すると知った。

_GitHub - Largo/ocran: One-Click Ruby Application Builder
_ocran | RubyGems.org | コミュニティのgemホスティングサービス

ちなみに、過去には ocra2 という fork版もあったらしいけど、それは消滅したらしい。

_ocra2 | RubyGems.org | コミュニティのgemホスティングサービス

ocran なら違った結果になるのだろうか? ocran を Ruby 3.2.2 x86 でインストールしてみた。
gem install ocran
ocran 1.3.14 がインストールされた。

LibUI を使った Rubyスクリプトを ocran でexe化してみた。
ocran 01_hello_libui.rb
01_hello_libui.exe が生成できた。実行したところ動いてくれた。

FXRuby を使った Rubyスクリプトはどうだろう。
ocran 01_hellofxruby.rb
これもexeが生成できたし、実行することもできた。

つまり、LibUI、FXRuby に関しては、ocran を使うことで、Ruby 3.2.2 x86 でもexe化できると分かった。

では、gtk3 を使ったRubyスクリプトはどうだろう。試してみた。
ocran 08_image2.rb images

exeは生成できたが…。
> 08_image2.exe
<internal:C:/Users/(USERNAME)/AppData/Local/Temp/ocrC540.tmp/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:86:in `require': 126: 指定されたモジュールが見つかりません。   - C:/Users/(USERNAME)/AppData/Local/Temp/ocrC540.tmp/lib/ruby/gems/3.2.0/gems/
glib2-4.2.0/lib/glib2.so (LoadError)
        from <internal:C:/Users/(USERNAME)/AppData/Local/Temp/ocrC540.tmp/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:86:in `require'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocrC540.tmp/lib/ruby/gems/3.2.0/gems/glib2-4.2.0/lib/glib2.rb:117:in `<top (required)>'
        from <internal:C:/Users/(USERNAME)/AppData/Local/Temp/ocrC540.tmp/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:86:in `require'
        from <internal:C:/Users/(USERNAME)/AppData/Local/Temp/ocrC540.tmp/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:86:in `require'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocrC540.tmp/lib/ruby/gems/3.2.0/gems/gobject-introspection-4.2.0/lib/gobject-introspection.rb:17:in `<top (required)>'
        from <internal:C:/Users/(USERNAME)/AppData/Local/Temp/ocrC540.tmp/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:86:in `require'
        from <internal:C:/Users/(USERNAME)/AppData/Local/Temp/ocrC540.tmp/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:86:in `require'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocrC540.tmp/lib/ruby/gems/3.2.0/gems/atk-4.2.0/lib/atk.rb:17:in `<top (required)>'
        from <internal:C:/Users/(USERNAME)/AppData/Local/Temp/ocrC540.tmp/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:86:in `require'
        from <internal:C:/Users/(USERNAME)/AppData/Local/Temp/ocrC540.tmp/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:86:in `require'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocrC540.tmp/lib/ruby/gems/3.2.0/gems/gtk3-4.2.0/lib/gtk3.rb:17:in `<top (required)>'
        from <internal:C:/Users/(USERNAME)/AppData/Local/Temp/ocrC540.tmp/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:160:in `require'
        from <internal:C:/Users/(USERNAME)/AppData/Local/Temp/ocrC540.tmp/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:160:in `rescue in require'
        from <internal:C:/Users/(USERNAME)/AppData/Local/Temp/ocrC540.tmp/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:40:in `require'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocrC540.tmp/src/08_image2.rb:14:in `<main>'
<internal:C:/Users/(USERNAME)/AppData/Local/Temp/ocrC540.tmp/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:86:in `require': cannot load such file -- gtk3 (LoadError)
        from <internal:C:/Users/(USERNAME)/AppData/Local/Temp/ocrC540.tmp/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:86:in `require'
        from C:/Users/(USERNAME)/AppData/Local/Temp/ocrC540.tmp/src/08_image2.rb:14:in `<main>'

glib2.so が見つからないし gtk3 も使えないと言ってきた。残念。

それでも、Ruby 3.x 以降は、ocra ではなく fork版の ocran を使えばexe化できる可能性があると分かった。

ただし、ocran を使えばあらゆるRubyスクリプトがexe化できるわけでもなく…。FXRuby や LibUI を使ったスクリプトはexe化できても、gtk3 を使ったスクリプトはexe化できない、ということも分かった。

結論としては…。Ruby なんて窓から投げ捨てろ。Python 使おうぜ。いや、日本語とオサラバさえすれば Ruby + FXRuby が使えると思うし、画像表示を諦めれば Ruby + LibUI も使えると思うけど…。

Ruby が Tk を切り捨ててしまったのが結構痛い気がする。もっとも、Windows上で Ruby + Tk が動くようにするのって一苦労だし。というか現状ではもう動かし方すら分らんし。

2023/10/20追記 :

現状の Ruby + Windows で Ruby/Tk を動かす方法が分からないと書いてしまったけど、DevKit付のRubyをインストールしてあるなら、gem install tk で利用できるようになるらしいと分かった。そのあたりは別記事でメモ。

以上です。

過去ログ表示

Prev - 2023/10 - Next
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31

カテゴリで表示

検索機能は Namazu for hns で提供されています。(詳細指定/ヘルプ


注意: 現在使用の日記自動生成システムは Version 2.19.6 です。
公開されている日記自動生成システムは Version 2.19.5 です。

Powered by hns-2.19.6, HyperNikkiSystem Project