Sunday, May 24, 2009

The OCRA Compiler: Tips, Tricks, and Gotchas

I've previously mentioned Lars Christensen's One-Click Ruby Application Builder, a "compiler" for Ruby scripts that shows a lot of potential (and current value). There's not much documentation yet, but folks are installing it, using it, and providing feedback. It works right out of the box for many purposes, but here are a few things to keep in mind as you use it...

"Failed to create directory" Error

One user reported receiving the error "Failed to create directory" when running the compiled executable. As a possible workaround, try running ocra.rb from the directory where your script is located. For example, instead of running...


ocra.rb "C:\code\rubyscripts\application.rbw"

...navigate to the "C:\code\rubyscripts" directory, then run:

ocra.rb application.rbw

Note that while this resolved the problem on my machine, it didn't help the person who originally reported the problem.

Require RubyGems

When you compile your script (which uses one or more gems) with OCRA and then run the executable, you may receive a 'no such file to load' error. Try adding the line...

require 'rubygems'

...to the top of your script, above the other require statements. I've found that a script that runs pre-compiled without this statement may not execute once compiled.

Compile Without Running

I mentioned earlier that it would be nice to have an option to avoid fully running the script, similar to RubyScript2Exe's exit if RUBYSCRIPT2EXE.is_compiling? idiom. A tip of the hat goes to reader "BackOrder", who offered the following solution:

exit if Object.const_defined?(:Ocra)

Put all your require statements at the top of your code, followed by this line.

OCRA and Mechanize: "libxml2.dll not found"

There may be a problem compiling a script that requires the mechanize gem. Running the compiled executable resulted in a "libxml2.dll was not found" error on my machine.

Note that the above observations relate to version 1.0.2 (current as of this writing) of the ocra gem.

More information is available in the OCRA forums and bug tracker.

Thanks again to Lars for creating OCRA, and to the users who have installed it, used it, and provided their feedback.

Thanks for stopping by!

7 comments:

funkyrhodes said...

Thanks for this. I'm still getting a 'No such file to load' in regards to win32ole, even after I placed require 'rubygems' at the top of the script. Do you have any other suggestions?

John said...

@funky: If you are also loading in the watir gem, you will get these kinds of errors. Seems watir loads its own version of win32ole that will cause issues if you also try to load your version of win32ole. Comment out the win32ole require and try compiling again and see what happens.

@Dave: I also get errors for the autoitx3.dll file when doing an ocra compile with watir. Trying to figure out if there is a way to temporarily register or otherwise use this dll from an ocra-compiled program. If anyone knows a way, please let me know!

John said...

Ok, I figured out the AutoItX3.dll issue here.

Blueeyes said...

@John: I tried "Comment out the win32ole require and try compiling again" but it's not work.
I user WIN32OLE.new("excel.application")
so
I need require 'win32ole'
Help me

Blueeyes said...

@John: I tried "Comment out the win32ole require and try compiling again" but it's not work.
I user WIN32OLE.new("excel.application")
so
I need require 'win32ole'
Help me

Brad Fallon said...

Is there a way to make alt tab only switch between active windows in the current application?

Lo Yuk Fai said...

Hi,

I'm trying to build a portable version of PDFBeads but have encountered some errors, any chance you can take a look and give some advices...?

The information is posted at http://rubyforge.org/forum/forum.php?thread_id=49941&forum_id=31710

Cheers.

Lo Yuk Fai