0

have a problem with compressing my script.

I have a main.rb and some classes in subfolders like Subfolder/Class.rb In my main.rb, I have the Classes declared like that:

require './Subfolder/Class.rb'

When I just run my main script, it works. Also my exe works, when it is in the same place as the main.rb.
But when I put the exe somewhere else I get this error:

C:/Users/MLEING~1/AppData/Local/Temp/ocr53C2.tmp/lib/ruby/site_ruby/1.9.1/rubyge
ms/custom_require.rb:36:in `require': cannot load such file -- ./Parsing/Calibra
tionState (LoadError) from C:/Users/MLEING~1/AppData/Local/Temp/ocr53C2.tmp/lib/ruby/site_ruby
/1.9.1/rubygems/custom_require.rb:36:in `require'
    from C:/Users/MLEING~1/AppData/Local/Temp/ocr53C2.tmp/src/main.rb:9:in `
<main>'

Can I somehow put the dependencies into my exe?
I also tried to include them like that:

ocra main.rb Subfolder/*.rb

But it doesn't help.

madmax
  • 1,803
  • 3
  • 25
  • 50

2 Answers2

1

Have you tried making a ruby gem out of your project? http://guides.rubygems.org/make-your-own-gem/

Gems define their own dependencies.

Richard Brown
  • 11,346
  • 4
  • 32
  • 43
-1

Your require is using a relative path from the current directory (which you can see because it starts with "./"

Instead, try:

require 'Subfolder/Class.rb'

And make sure $LOAD_PATH includes the location where all of your ruby code is unpacked (which you can look at by examining $0 (or figure out the full path from $0 and require the .rb with a full path)

  • Why the downvote? ocra may unpack the libraries in a different path than what it sets current directory to (as has been my experience) and then set the LOAD_PATH properly. So the "./" at the beginning of the require can ruin everything since it doesn't allow moving of libraries. Making a gem is lovely and all, but not necessary just because you want to require code in ocra. – David Ljung Madison Stellar Jan 24 '15 at 13:06