# Problems with 'require' in embedded ruby

**URL:** <https://rubytalk.org/t/problems-with-require-in-embedded-ruby/53141>\
**Category:** ruby-talk\
**Created:** [29 April 2009 23:27 UTC](https://rubytalk.org/t/problems-with-require-in-embedded-ruby/53141 "2009-04-29T23:27:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![James\_Hughes1](https://avatars.discourse-cdn.com/v4/letter/j/ee59a6/32.png) [@James\_Hughes1](https://rubytalk.org/u/James_Hughes1)\
**Post date:** [29 April 2009 23:27 UTC](https://rubytalk.org/t/problems-with-require-in-embedded-ruby/53141/1 "2009-04-29T23:27:39Z")

</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[]) {  
&nbsp;&nbsp;VALUE result;  
&nbsp;&nbsp;ruby\_sysinit(&argc, &argv);  
&nbsp;&nbsp;RUBY\_INIT\_STACK;  
&nbsp;&nbsp;ruby\_init();  
&nbsp;&nbsp;ruby\_init\_loadpath();  
#ifdef \_DEBUG  
&nbsp;&nbsp;rb\_eval\_string("puts $LOAD\_PATH");  
#endif  
&nbsp;&nbsp;rb\_require("rules");

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return ruby\_cleanup(0);  
}

==== rules.rb ====

puts $LOAD\_PATH

require 'pp'

class Rules  
&nbsp;&nbsp;def self.apply(arr\_face)  
&nbsp;&nbsp;&nbsp;&nbsp;puts "array: #{arr\_face.size}" if arr\_face.kind\_of?(Array)  
&nbsp;&nbsp;&nbsp;&nbsp;puts arr\_face.pretty\_inspect  
&nbsp;&nbsp;&nbsp;&nbsp;return (arr\_face.size \> 0) ? 1 : 0  
&nbsp;&nbsp;end  
end

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![James\_Hughes1](https://avatars.discourse-cdn.com/v4/letter/j/ee59a6/32.png) [@James\_Hughes1](https://rubytalk.org/u/James_Hughes1)\
**Post date:** [30 April 2009 00:08 UTC](https://rubytalk.org/t/problems-with-require-in-embedded-ruby/53141/2 "2009-04-30T00:08:36Z")

</div>

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).
> 
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![David\_Marchaland](https://avatars.discourse-cdn.com/v4/letter/d/ba9def/32.png) [@David\_Marchaland](https://rubytalk.org/u/David_Marchaland)\
**Post date:** [7 February 2010 15:53 UTC](https://rubytalk.org/t/problems-with-require-in-embedded-ruby/53141/3 "2010-02-07T15:53:14Z")

</div>

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).
> 
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).
