# Ruby 1.9 evaled from C doesn't load libraries properly

**URL:** <https://www.ruby-forum.com/t/ruby-1-9-evaled-from-c-doesnt-load-libraries-properly/173525>\
**Category:** Ruby\
**Created:** [August 10, 2009, 11:51pm UTC](https://www.ruby-forum.com/t/ruby-1-9-evaled-from-c-doesnt-load-libraries-properly/173525 "2009-08-10T23:51:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexmic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/977dab/32.png) [@alexmic](https://www.ruby-forum.com/u/alexmic)\
**Post date:** [August 10, 2009, 11:51pm UTC](https://www.ruby-forum.com/t/ruby-1-9-evaled-from-c-doesnt-load-libraries-properly/173525/1 "2009-08-10T23:51:56Z")

</div>

Ok, so I’m using C++ in a project called Titanium and trying to evaluate  
Ruby (1.9).

The code looks something like this:

```
ruby_init();
ruby_init_loadpath();
rb_set_safe_level(0);
      ruby_script("ruby");
rb_eval_string_protect(code, &error);

```

So, this can parse Ruby fine, the only issue is when I require the mutex  
lib (needed by Rubygems).

The error I get is: undefined method `synchronize’ for #Mutex:0x1f8cf4

It looks like the mutex class (which is written in C) isn’t getting  
loaded properly. Anybody got any ideas as to why?

---

<div class="post-metadata">

**Author:** ![alexmic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/977dab/32.png) [@alexmic](https://www.ruby-forum.com/u/alexmic)\
**Post date:** [August 13, 2009, 12:33am UTC](https://www.ruby-forum.com/t/ruby-1-9-evaled-from-c-doesnt-load-libraries-properly/173525/2 "2009-08-13T00:33:29Z")

</div>

I should add that other libraries written in C, like StringIO, work  
fine.

Alex M. wrote:

> Ok, so I’m using C++ in a project called Titanium and trying to evaluate  
> Ruby (1.9).
> 
> The code looks something like this:
> 
> ```
> ruby_init();
> ruby_init_loadpath();
> rb_set_safe_level(0);
> ruby_script("ruby");
> rb_eval_string_protect(code, &error);
> 
> ```
> 
> So, this can parse Ruby fine, the only issue is when I require the mutex  
> lib (needed by Rubygems).
> 
> The error I get is: undefined method `synchronize’ for #Mutex:0x1f8cf4
> 
> It looks like the mutex class (which is written in C) isn’t getting  
> loaded properly. Anybody got any ideas as to why?

---

<div class="post-metadata">

**Author:** ![alexmic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/977dab/32.png) [@alexmic](https://www.ruby-forum.com/u/alexmic)\
**Post date:** [August 13, 2009, 12:39am UTC](https://www.ruby-forum.com/t/ruby-1-9-evaled-from-c-doesnt-load-libraries-properly/173525/3 "2009-08-13T00:39:21Z")

</div>

On Aug 10, 2009, at 14:52, Alex M. wrote:

> rb\_eval\_string\_protect(code, &error);
> 
> So, this can parse Ruby fine, the only issue is when I require the  
> mutex  
> lib (needed by Rubygems).

RubyGems requires thread by itself, why are you doing it? Why not  
require ‘rubygems’?

---

<div class="post-metadata">

**Author:** ![alexmic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/977dab/32.png) [@alexmic](https://www.ruby-forum.com/u/alexmic)\
**Post date:** [August 13, 2009, 12:43am UTC](https://www.ruby-forum.com/t/ruby-1-9-evaled-from-c-doesnt-load-libraries-properly/173525/4 "2009-08-13T00:43:56Z")

</div>

Eric H. wrote:

> On Aug 10, 2009, at 14:52, Alex M. wrote:
> 
> > rb\_eval\_string\_protect(code, &error);
> > 
> > So, this can parse Ruby fine, the only issue is when I require the  
> > mutex  
> > lib (needed by Rubygems).
> 
> RubyGems requires thread by itself, why are you doing it? Why not  
> require ‘rubygems’?

When I require ‘rubygems’ I get that error - I traced it back to the  
Mutex lib in the thread lib.  
In other words, rubygems won’t work.

Also, peculiarly, if I stub out the schedule method on Mutex like this:

require ‘thread’  
class ::Mutex  
def synchronize  
yield  
end  
end

Then rubygems seems to load fine, but any other gems, such as  
activesupport won’t load through rubygems.

It’s really odd…
