gem ocra 生成大文件

gem ocra generates huge files

我创建了一个简单的 ruby 脚本

require 'gtk3'

def destroy( widget )
   Gtk.main_quit
end

Gtk.init
window = Gtk::Window.new :toplevel
window.set_title( "helloworld.rb" )
window.set_border_width( 10 )

window.signal_connect( "delete_event" ) {
   destroy(nil)
}

button = Gtk::Button.new :label => "Button"
window.add( button )
button.show
window.show
Gtk.main

此脚本创建一个带有按钮的非常简单的 GUI。如果我使用 ocra gem 通过命令

创建 script.exe
ocra script.rbw

生成了一个 70 MB 的文件,对于带有按钮的简单 window 来说太大了。 我究竟做错了什么?我能做些什么来消除这个障碍? Ocra输出是这样的(用命令"ocra script.rb"而不是"ocra script.rbw"输出,但是过程是一样的)

=== Loading script to check dependencies
=== Attempting to trigger autoload of Gem::ConfigFile
=== Attempting to trigger autoload of Gem::DependencyList
=== Attempting to trigger autoload of Gem::DependencyResolver
=== Attempting to trigger autoload of Gem::Installer
=== Attempting to trigger autoload of Gem::RequestSet
=== Attempting to trigger autoload of Gem::Source
=== Attempting to trigger autoload of Gem::SourceList
=== Attempting to trigger autoload of Gem::SpecFetcher
=== Attempting to trigger autoload of CGI::HtmlExtension
=== Detected gem ocra-1.3.4 (loaded, files)
===     6 files, 191218 bytes
=== Detected gem pkg-config-1.1.6 (loaded, files)
===     3 files, 29263 bytes
=== Detected gem cairo-1.14.1-x64-mingw32 (loaded, files)
===     572 files, 80204194 bytes
=== Detected gem glib2-2.2.4-x64-mingw32 (loaded, files)
===     2115 files, 104593625 bytes
=== Detected gem gobject-introspection-2.2.4-x64-mingw32 (loaded, files)
===     231 files, 13768036 bytes
=== Detected gem gio2-2.2.4-x64-mingw32 (loaded, files)
===     3 files, 49152 bytes
=== Detected gem atk-2.2.4-x64-mingw32 (loaded, files)
===     208 files, 4281497 bytes
=== Detected gem pango-2.2.4-x64-mingw32 (loaded, files)
===     465 files, 95081429 bytes
=== Detected gem gdk_pixbuf2-2.2.4-x64-mingw32 (loaded, files)
===     188 files, 5588250 bytes
=== Detected gem cairo-gobject-2.2.4-x64-mingw32 (loaded, files)
===     5 files, 95261 bytes
=== Detected gem gdk3-2.2.4-x64-mingw32 (loaded, files)
===     3841 files, 114129504 bytes
=== Detected gem gtk3-2.2.4-x64-mingw32 (loaded, files)
===     42 files, 2942499 bytes
=== Detected gem io-console-0.4.2 (loaded, files)
=== WARNING: Gem io-console-0.4.2 root folder was not found, skipping
=== Including 53 encoding support files (3576320 bytes, use --no-enc to exclude)

DL is deprecated, please use Fiddle
=== Building example.exe
=== Adding user-supplied source files
=== Adding ruby executable ruby.exe
=== Adding detected DLL C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/cairo-1.14.1-x64-
mingw32/vendor/local/bin/libcairo-2.dll
=== Adding detected DLL C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/cairo-1.14.1-x64-
......
=== Adding detected DLL C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/gdk_pixbuf2-2.2.4
-x64-mingw32/vendor/local/bin/libgdk_pixbuf-2.0-0.dll
=== Adding detected DLL C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/gdk3-2.2.4-x64-mi
ngw32/vendor/local/bin/libgdk-3-0.dll
=== Adding detected DLL C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/gdk3-2.2.4-x64-mi
ngw32/vendor/local/bin/libgtk-3-0.dll
=== Adding detected DLL C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/pango-2.2.4-x64-m
ingw32/vendor/local/lib/pango/1.8.0/modules/pango-basic-win32.dll
=== Adding detected DLL C:/Ruby21-x64/bin/LIBEAY32.dll
=== Adding detected DLL C:/Ruby21-x64/bin/SSLEAY32.dll
=== Adding library files
=== Compressing 519431948 bytes
=== Finished building example.exe (95218080 bytes)

我用 cli 尝试相同的过程 script.rb

puts "Hello World"

结果:2,6 Mb 仅用于打印 Hello World。 我能做什么?

Ocra 不是编译器,它是一种准备就绪-运行-ruby。它需要 ruby,所有加载的 gem 和脚本并将它们打包在一起。

当您调用 exe 时,它​​会提取所有内容并调用包含 ruby 的 ruby-脚本。脚本执行后,它会删除所有内容。如果您的脚本失败,则说明删除未完成,您会在临时目录中找到很多文件。

在您的情况下 require 'gtk3' gtk3 支持的所有内容都已加载。好像很多。

你的 Hello World 的 2.6MB 不仅包含屏幕输出,还包含 ruby 能够做的所有事情 - 即使它没有被执行,

你能做什么?找个版本吧,不需要那么多。