rubyocra

How do I make ruby ocra work with multiple source file?


I'm using ocra to convert my rb scripts to exe, but if it has multiple sources, the exe will show the LoadError complaining it can't find the other source files.

For example, in my main.rb:

require_relative 'lib/user'
# blabla bla

after I packing my main it with either ocra main.rb ocra main.rb ./lib/user.rb, then run the main.exe elsewhere and it says cannot load such file -- lib/user (LoadError)

How do I make it work with multiple sources?


Solution

  • OK so I missed this from the manual...

    OCRA does not set up the include path. Use $:.unshift File.dirname($0) at the start of your script if you need to 'require' additional source files from the same directory as your main script.

    added $:.unshift File.dirname($0) at the start of my entry script, also changed my require './somescript' to require 'somescript' then it works