Load Error with Executable

4 views
Skip to first unread message

blamemike

unread,
May 12, 2009, 6:16:07 PM5/12/09
to New Gem Generator
Hi all,

I have a quick (hopefully) question/issue regarding generating an
executable. So I built up my gem using rake repackage, and installed
with rake install_gem, which is all good. The problem is the
executable I have in /bin is not working correctly. When I try to call
my gem command name from console I get the following:

/usr/local/bin/my_gem_name_here:19:in `load': no such file to load --
my_gem_name_here (LoadError)

The file in /usr/local/bin looks like:

#!/usr/local/bin/ruby
#
# This file was generated by RubyGems.
#
# The application 'my_gem_name_here' is installed as part of a gem,
and
# this file is here to facilitate running it.
#

require 'rubygems'

version = ">= 0"

if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then
version = $1
ARGV.shift
end

gem 'my_gem_name_here', version
load 'my_gem_name_here'

It was my understanding that having a script with no extension in bin
should allow the app to be run from the command line. Am I missing
something simple?

Thanks so much for any help.


Graham Agnew

unread,
May 12, 2009, 6:56:41 PM5/12/09
to new-gem-...@googlegroups.com
Hi,

It's finding your executable and loading it into Ruby, but it's
failing on the call to 'gem' on line 19 of your script. Are you sure
that your gem has installed properly? Typically there would be a file
lib/my_gem_name_here.rb installed as part of your gem. On my Mac
which has Ruby from MacPorts installed, the rake gem is in the
directory "/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.4" and there is
a "lib/rake.rb" under there.

I hope this helps.

Cheers,
Gra.

blamemike

unread,
May 12, 2009, 7:36:10 PM5/12/09
to New Gem Generator
Hi Gra,

Thanks for the response. I've tried this in irb:

irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> gem 'my_gem'
=> true
irb(main):003:0> load 'my_gem'
LoadError: no such file to load -- my_gem
from (irb):3:in `load'
from (irb):3

Also, line 19 is the load statement, not the gem statement.

Graham Agnew

unread,
May 13, 2009, 2:55:49 AM5/13/09
to new-gem-...@googlegroups.com
Hi blamemike,

Ah yes, I'm not sure you need to use 'load'. Having done the
'gem' (or 'require') to load the lib/my_gem.rb, shouldn't you just be
calling methods declared in that file? The 'load' is useful for
executing another script, and it has an optional parameter that will
run the script in an anonymous module so that the script doesn't foul
up the caller's object space.

If the lib/my_gem.rb is the actual executable script you want to run,
then either it should be in your gem as an executable, or the code
that you want to execute should be in a method that you can call once
the lib/my_gem.rb has been 'require'd.

Cheers,
Gra.

Michael Leung

unread,
May 13, 2009, 3:01:00 AM5/13/09
to new-gem-...@googlegroups.com
Hey Graham,

Actually the load call is automatic. So when you install a gem that
has a script in bin, it automatically makes a file in /usr/local/ bin
for that executable so it's in your path. The load call is
automatically in there. The weirdest thing is, my friend grabbed my
gem hasn't run into this issue. it's something to do with my machine.

So odd.

Thanks again.
Reply all
Reply to author
Forward
0 new messages