将ruby脚本编译成exe吗? [英] Compile ruby script into exe?

查看:250
本文介绍了将ruby脚本编译成exe吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在Windows上将ruby脚本编译成.exe?我到处搜索,并尝试了以下操作(看起来RubyScript2EXE,Shoes和Crate似乎都死了或被抛弃了。):

Is it possible to compile a ruby script into an .exe on Windows? I have searched everywhere and I've tried the following (It looked like RubyScript2EXE, Shoes and Crate all seemed dead or abandoned.):


  1. http://ocra.rubyforge.org/

  2. http://exerb.sourceforge.jp/index.en.html

  1. http://ocra.rubyforge.org/
  2. http://exerb.sourceforge.jp/index.en.html

我正在Windows 7 Ultimate(64位)系统上使用Ruby 1.8.7,运行的是干净系统:

I'm using Ruby 1.8.7 on Windows 7 Ultimate (64bit.) from a clean system I do this:


  1. 从rubyinstaller.org安装RubyInstaller 1.8.7-p358

  2. gem install watir

  3. gem install ocra

  4. git克隆git://github.com/snaury/exerb-mingw.git

  5. cd exerb-mingw

  6. ruby​​ setup.rb

  1. Install RubyInstaller 1.8.7-p358 from rubyinstaller.org
  2. gem install watir
  3. gem install ocra
  4. git clone git://github.com/snaury/exerb-mingw.git
  5. cd exerb-mingw
  6. ruby setup.rb

我有一个相当简单的脚本来执行此操作:

I have a fairly simple script that does this:

require 'rubygems'
require 'watir'
browser = Watir::Browser.new
browser.goto 'http://slashdot.org'

当我运行Ocra时,我没有收到任何错误消息,并且什么也没有发生:

When I run Ocra I don't get any error messages, and nothing happens:

ocra --output test.exe test.rb
=== Loading script to check dependencies

Exerb似乎是一个更好的解决方案,因为它可以编译为rbc,并且确实可以执行以下操作:

Exerb seems like a better solution since it compiles to rbc, and it does actually do something:

ruby -r exerb/mkexy test.rb
# Window pops up and after I close it it writes out test.exy
C:\Users\jonathan\dev\Citation>exerb test.exy
C:/Ruby187/lib/ruby/site_ruby/1.8/exerb/recipe.rb:146:in `add_file_entry': test.
exy: no such file -- C:/Ruby187/lib/ruby/gems/1.8/gems/win32-api-1.4.8-x86-mingw32/lib/win32/ruby18/win32/api.so (RuntimeError)
    from C:/Ruby187/lib/ruby/site_ruby/1.8/exerb/recipe.rb:86:in `create_archive'
    from C:/Ruby187/lib/ruby/site_ruby/1.8/exerb/recipe.rb:85:in `each'
    from C:/Ruby187/lib/ruby/site_ruby/1.8/exerb/recipe.rb:85:in `create_archive'
    from C:/Ruby187/bin/exerb.bat:67:in `main'
    from C:/Ruby187/bin/exerb.bat:196

所以找不到win32 / api.so。当我查看C:/Ruby187/lib/ruby/site_ruby/1.8/exerb/recipe.rb时,看起来宝石不在搜索路径中:

So it can't find win32/api.so. When I look in C:/Ruby187/lib/ruby/site_ruby/1.8/exerb/recipe.rb it looks like gems are not in the search path:

DIR: C:/Users/jonathan/dev/Citation
DIR: C:/Ruby187/lib/ruby/site_ruby/1.8
DIR: C:/Ruby187/lib/ruby/site_ruby/1.8/i386-msvcrt
DIR: C:/Ruby187/lib/ruby/site_ruby
DIR: C:/Ruby187/lib/ruby/vendor_ruby/1.8
DIR: C:/Ruby187/lib/ruby/vendor_ruby/1.8/i386-msvcrt
DIR: C:/Ruby187/lib/ruby/vendor_ruby
DIR: C:/Ruby187/lib/ruby/1.8
DIR: C:/Ruby187/lib/ruby/1.8/i386-mingw32
DIR: .

因此,在四处搜寻之后,我发现您可以像这样在exy文件中添加搜索路径:

So after digging around I found out you can add search paths in the exy file like so:

path:
  - C:/Ruby187/lib/ruby/gems/
  - C:/Ruby187/lib/ruby/gems/1.8
  - C:/Ruby187/lib/ruby/gems/1.8/gems

此后,它确实在search_path中显示了这些路径,但仍然给我同样的错误。显然,必须有某种方法才能使rubygems路径包含在exy中?

After this it does show these paths in search_path, but it still gives me the same error. Obviously there must be some way to get rubygems paths to be included in the exy?

那么,如今有人如何在Windows上构建.exe?

So, how does someone build a .exe on Windows these days?

我在Exerb上取得了一些进展,我发现您可以使用-rrubygems选项运行mkexy来实现这一点。这对于大多数ruby项目都非常有用。我已经尝试了一些ruby脚本,这些脚本使用许多不同的库而没有问题。例如:

I made some progress with Exerb, I found out you can run mkexy with the -rrubygems option to pull this in. And this works GREAT for most ruby projects. I've tried it for a few ruby scripts that use a number of different libraries without problems. For example:

mkexy -rrubygems test.rb
exerb test.exy
test.exe === WORKS!

不幸的是,这对watir无效。当我运行使用watir构建的.exe时,会得到以下信息:

Unfortunately, it doesn't work for watir. When I run an .exe built with watir I get the following:

s4t-utils/claims.rb:24:in `user_is_bewildered': Error in the default values: :br

owser的值必须是 safari之一, 'firefox'或'ie'和''看起来并不正确。 (StandardError)

owser's value must be one of 'safari', 'firefox', or 'ie', and '' doesn't look r ight. (StandardError)

推荐答案

https://github.com/rdp/ruby_tutorials_core/wiki/ruby-talk-faq#wiki-ruby_to_exe 一次是它们的列表。

这篇关于将ruby脚本编译成exe吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆