# Problems with 'require' in embedded ruby

**URL:** <https://www.ruby-forum.com/t/problems-with-require-in-embedded-ruby/166838>\
**Category:** Ruby\
**Created:** [April 30, 2009, 1:27am UTC](https://www.ruby-forum.com/t/problems-with-require-in-embedded-ruby/166838 "2009-04-30T01:27:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sjames](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c57346/32.png) [@sjames](https://www.ruby-forum.com/u/sjames)\
**Post date:** [April 30, 2009, 1:27am UTC](https://www.ruby-forum.com/t/problems-with-require-in-embedded-ruby/166838/1 "2009-04-30T01:27:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sjames](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c57346/32.png) [@sjames](https://www.ruby-forum.com/u/sjames)\
**Post date:** [April 30, 2009, 2:08am UTC](https://www.ruby-forum.com/t/problems-with-require-in-embedded-ruby/166838/2 "2009-04-30T02:08:26Z")

</div>

Sorry, forgot to mention: ruby 1.9.1-p0 compiled from source running on  
Vista.

James H. 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).

---

<div class="post-metadata">

**Author:** ![sjames](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c57346/32.png) [@sjames](https://www.ruby-forum.com/u/sjames)\
**Post date:** [February 7, 2010, 4:53pm UTC](https://www.ruby-forum.com/t/problems-with-require-in-embedded-ruby/166838/3 "2010-02-07T16:53:10Z")

</div>

Hi James,

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

Thanks,  
David

James H. wrote:

> Sorry, forgot to mention: ruby 1.9.1-p0 compiled from source running on  
> Vista.
> 
> James H. 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).
