# C embedding problem with 1.9

**URL:** <https://www.ruby-forum.com/t/c-embedding-problem-with-1-9/185420>\
**Category:** Ruby\
**Created:** [March 19, 2010, 4:07pm UTC](https://www.ruby-forum.com/t/c-embedding-problem-with-1-9/185420 "2010-03-19T16:07:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tibur](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/a8b319/32.png) [@tibur](https://www.ruby-forum.com/u/tibur)\
**Post date:** [March 19, 2010, 4:07pm UTC](https://www.ruby-forum.com/t/c-embedding-problem-with-1-9/185420/1 "2010-03-19T16:07:47Z")

</div>

Hello.

I can’t manage to make the attached program to work with ruby 1.9.

When I run the program, it complain about unknown variable ‘a’. Here is  
the exact error.

undefined local variable or method `a’ for main:Object

If I compile it using ruby 1.8, it works perfectly.

It occurs both on win32 and Ubuntu 9.10.  
I tried ruby-1.9.1p243 on linux, and ruby-1.9.1-p376 on windows. I also  
tried using a fresh build of the last version from the ruby CVS.

Any idea about the initialization error I certainly made ?

Thanks,  
Thibaut

---

<div class="post-metadata">

**Author:** ![tibur](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/a8b319/32.png) [@tibur](https://www.ruby-forum.com/u/tibur)\
**Post date:** [March 19, 2010, 4:23pm UTC](https://www.ruby-forum.com/t/c-embedding-problem-with-1-9/185420/2 "2010-03-19T16:23:45Z")

</div>

It seems that using a global variable by adding $ before the ‘a’  
variable name solve the problem.

---

<div class="post-metadata">

**Author:** ![tibur](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/a8b319/32.png) [@tibur](https://www.ruby-forum.com/u/tibur)\
**Post date:** [March 19, 2010, 5:05pm UTC](https://www.ruby-forum.com/t/c-embedding-problem-with-1-9/185420/3 "2010-03-19T17:05:31Z")

</div>

I am still stucked. The follwing code produce the error :  
undefined method `synchronize’ for #Mutex:0x83b858c

int main(int argc, char \*\* argv){  
int state;  
ruby\_sysinit(&argc, &argv);

RUBY\_INIT\_STACK  
ruby\_init();

ruby\_init\_loadpath();  
ruby\_script(“embed”);

rb\_eval\_string\_protect("$mutex = Mutex.new", &state);  
checkRubyError(state);

rb\_eval\_string\_protect("$mutex.synchronize() { }", &state);  
checkRubyError(state);

return 0;  
}
