把ruby程序转变为windows下的exe可执行文件可以用以下gem
exerb
rubyscript2exe
ocra
我们重点介绍 ocra
https://github.com/larsch/ocra
安装方法(安装完ruby-windows,就自带gem了):
gem install ocra
ruby代码:
hw.rb
put “Hello world!”
打包:
ocra hw.rb
测试:
hw.exe
常用选项:
–windows 可以不显示控制台
–no-autodll 不包含依赖的dll库,可以把需要的dll放在执行目录下
–no-lzma 不压缩执行文件
–icon <ico> 指定icon图标
———————
C:\Users\ThinkPad\Desktop>ocra 26887.rb
=== Loading script to check dependencies
usage: ./rpcbind_udp_crash_poc.rb <target>
=== Attempting to trigger autoload of Gem::SpecFetcher
=== Attempting to trigger autoload of Gem::BundlerVersionFinder
=== Attempting to trigger autoload of Gem::SourceList
=== Attempting to trigger autoload of Gem::ConfigFile
=== Attempting to trigger autoload of Gem::Licenses
=== Attempting to trigger autoload of Gem::Installer
=== Attempting to trigger autoload of Gem::DependencyList
=== Attempting to trigger autoload of Module::IPAddr
=== Attempting to trigger autoload of RubyInstaller::Runtime::Components::Base
=== WARNING: RubyInstaller::Runtime::Components::Base was defined autoloadable, but caused NameError
=== Attempting to trigger autoload of RubyInstaller::Runtime::Ridk
=== Attempting to trigger autoload of RubyInstaller::Runtime::PACKAGE_VERSION
=== Attempting to trigger autoload of RubyInstaller::Runtime::ComponentsInstaller
=== Attempting to trigger autoload of CGI::HtmlExtension
=== Detected gem did_you_mean-1.2.0 (loaded, files)
=== 19 files, 38147 bytes
=== Detected gem ocra-1.3.10 (loaded, files)
=== 5 files, 210830 bytes
=== Detected gem zlib-1.0.0 (loaded, files)
=== WARNING: Gem zlib-1.0.0 root folder was not found, skipping
=== Detected gem stringio-0.0.1 (loaded, files)
=== WARNING: Gem stringio-0.0.1 root folder was not found, skipping
=== Detected gem date-1.0.0 (loaded, files)
=== WARNING: Gem date-1.0.0 root folder was not found, skipping
=== Detected gem fiddle-1.0.0 (loaded, files)
=== WARNING: Gem fiddle-1.0.0 root folder was not found, skipping
=== Detected gem etc-1.0.0 (loaded, files)
=== WARNING: Gem etc-1.0.0 root folder was not found, skipping
=== Detected gem fileutils-1.0.2 (loaded, files)
=== WARNING: Gem fileutils-1.0.2 root folder was not found, skipping
=== Detected gem openssl-2.1.2 (loaded, files)
=== WARNING: Gem openssl-2.1.2 root folder was not found, skipping
=== Detected gem ipaddr-1.2.0 (loaded, files)
=== WARNING: Gem ipaddr-1.2.0 root folder was not found, skipping
=== Detected gem rake-12.3.0 (loaded, files)
=== 44 files, 119604 bytes
=== Including 59 encoding support files (3790848 bytes, use --no-enc to exclude)
=== Building 26887.exe
=== Adding user-supplied source files
=== Adding ruby executable ruby.exe
=== Adding detected DLL C:/Ruby25-x64/bin/ruby_builtin_dlls/libgmp-10.dll
=== Adding detected DLL C:/Ruby25-x64/bin/ruby_builtin_dlls/libffi-6.dll
=== Adding detected DLL C:/Ruby25-x64/bin/ruby_builtin_dlls/zlib1.dll
=== Adding detected DLL C:/Ruby25-x64/bin/ruby_builtin_dlls/libssl-1_1-x64.dll
=== Adding detected DLL C:/Ruby25-x64/bin/ruby_builtin_dlls/libcrypto-1_1-x64.dll
=== Adding external manifest C:/Ruby25-x64/bin/ruby_builtin_dlls/ruby_builtin_dlls.manifest
=== Adding library files
=== Compressing 14108094 bytes
LZMA 4.65 : Igor Pavlov : Public domain : 2009-02-03
=== Finished building 26887.exe (3833370 bytes)