Forum: Ruby problems with 'require' in embedded ruby

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ee39e6dc0438826a59bb46877e5c70aa?d=identicon&s=25 James Hughes (jamezilla)
on 2009-04-30 01:27
I'm tinkering with my first C++ app with an embedded Ruby interpreter.
I'm having trouble with pretty much any usage of 'require' that involves
a file not in the same folder as the executable. If I use rb_require, it
blows up. If I do it in the script, it blows up.

I've checked the $LOAD_PATH variable on both the C++ side and the script
side, and it's reporting the values I expect. The modules I'm requiring
are definitely in the $LOAD_PATH directories.

I'm getting a memory access error. It's mostly trying to access address
0x0. Anyone have any inkling of what's going on here? My version of Ruby
wasn't compiled with symbols, so I can't see what's going on once the
code enters the interpreter (I'm not much for wading through
disassembly).

==== c++ ====

int main(int argc, char *argv[]) {
  VALUE result;
  ruby_sysinit(&argc, &argv);
  RUBY_INIT_STACK;
  ruby_init();
  ruby_init_loadpath();
#ifdef _DEBUG
  rb_eval_string("puts $LOAD_PATH");
#endif
  rb_require("rules");

        return ruby_cleanup(0);
}

==== rules.rb ====

puts $LOAD_PATH

require 'pp'

class Rules
  def self.apply(arr_face)
    puts "array: #{arr_face.size}" if arr_face.kind_of?(Array)
    puts arr_face.pretty_inspect
    return (arr_face.size > 0) ? 1 : 0
  end
end
Ee39e6dc0438826a59bb46877e5c70aa?d=identicon&s=25 James Hughes (jamezilla)
on 2009-04-30 02:08
Sorry, forgot to mention: ruby 1.9.1-p0 compiled from source running on
Vista.

James Hughes wrote:
> I'm tinkering with my first C++ app with an embedded Ruby interpreter.
> I'm having trouble with pretty much any usage of 'require' that involves
> a file not in the same folder as the executable. If I use rb_require, it
> blows up. If I do it in the script, it blows up.
>
> I've checked the $LOAD_PATH variable on both the C++ side and the script
> side, and it's reporting the values I expect. The modules I'm requiring
> are definitely in the $LOAD_PATH directories.
>
> I'm getting a memory access error. It's mostly trying to access address
> 0x0. Anyone have any inkling of what's going on here? My version of Ruby
> wasn't compiled with symbols, so I can't see what's going on once the
> code enters the interpreter (I'm not much for wading through
> disassembly).
706d611256db2e6f1108f0cdf96feee5?d=identicon&s=25 David Marchaland (marchaland)
on 2010-02-07 16:53
Hi James,

Did you solve this issue? I have a similar one with Ruby 1.8.7.

Thanks,
David

James Hughes wrote:
> Sorry, forgot to mention: ruby 1.9.1-p0 compiled from source running on
> Vista.
>
> James Hughes wrote:
>> I'm tinkering with my first C++ app with an embedded Ruby interpreter.
>> I'm having trouble with pretty much any usage of 'require' that involves
>> a file not in the same folder as the executable. If I use rb_require, it
>> blows up. If I do it in the script, it blows up.
>>
>> I've checked the $LOAD_PATH variable on both the C++ side and the script
>> side, and it's reporting the values I expect. The modules I'm requiring
>> are definitely in the $LOAD_PATH directories.
>>
>> I'm getting a memory access error. It's mostly trying to access address
>> 0x0. Anyone have any inkling of what's going on here? My version of Ruby
>> wasn't compiled with symbols, so I can't see what's going on once the
>> code enters the interpreter (I'm not much for wading through
>> disassembly).
This topic is locked and can not be replied to.