2

我创建了一个简单的 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 的文件,对于带有按钮的简单窗口来说太大了。我究竟做错了什么?我能做些什么来消除这个障碍?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。我能做些什么?

4

1 回答 1

2

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

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

在您的情况下,require 'gtk3'加载了 gtk3 支持的所有内容。似乎很多。

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

你可以做什么?尝试找到一个不需要太多的版本。

于 2015-02-02T09:18:14.520 回答