# Gem and ruby extension

**URL:** <https://www.ruby-forum.com/t/gem-and-ruby-extension/51193>\
**Category:** Ruby\
**Created:** [December 27, 2005, 9:36pm UTC](https://www.ruby-forum.com/t/gem-and-ruby-extension/51193 "2005-12-27T21:36:48Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![giom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/e56c9b/32.png) [@giom](https://www.ruby-forum.com/u/giom)\
**Post date:** [December 27, 2005, 9:36pm UTC](https://www.ruby-forum.com/t/gem-and-ruby-extension/51193/1 "2005-12-27T21:36:48Z")

</div>

I created a gem for a ruby C extension. Compiling the gem and  
installation goes find. When I try to run the test I get the following  
error:

[gus@comp ~]$ sudo  
ruby /usr/lib/ruby/gems/1.8/gems/Rulog-0.1.0/test/rulog.rb

Loaded suite /usr/lib/ruby/gems/1.8/gems/Rulog-0.1.0/test/rulog  
Started  
.ruby: symbol lookup  
error: /usr/lib/ruby/gems/1.8/gems/Rulog-0.1.0/lib/rulog.so: undefined  
symbol: rb\_mark

But, if I specify an include directory to ruby, it work:

[gus@comp ~]$ sudo ruby  
-I /usr/lib/ruby/gems/1.8/gems/Rulog-0.1.0/lib  
/usr/lib/ruby/gems/1.8/gems/Rulog-0.1.0/test/rulog.rb

Loaded suite /usr/lib/ruby/gems/1.8/gems/Rulog-0.1.0/test/rulog  
Started  
…  
Finished in 2.341459 seconds.

4 tests, 38 assertions, 0 failures, 0 errors

Duh! Why can’t it load rulog.so in the first case? The platform is ruby  
1.8.2 (2004-12-25) [i586-linux-gnu].

Any idea, pointers?

Guillaume.

---

<div class="post-metadata">

**Author:** ![giom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/e56c9b/32.png) [@giom](https://www.ruby-forum.com/u/giom)\
**Post date:** [December 27, 2005, 10:33pm UTC](https://www.ruby-forum.com/t/gem-and-ruby-extension/51193/2 "2005-12-27T22:33:18Z")

</div>

Guillaume M. wrote:

> Duh! Why can’t it load rulog.so in the first case? The platform is ruby  
> 1.8.2 (2004-12-25) [i586-linux-gnu].

Ruby is able to find libraries installed via RubyGems only after the  
rubygem library is loaded. You can accomplish in several ways,  
including setting an environment variable (RUBYOPT=rubygems), including  
-rubygems on your ruby command line, or even putting a ‘require  
“rubygems”’ in your source code. See  
[http://docs.rubygems.org/read/chapter/3#page70](http://docs.rubygems.org/read/chapter/3#page70) for details.

–  
– Jim W.

---

<div class="post-metadata">

**Author:** ![giom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/e56c9b/32.png) [@giom](https://www.ruby-forum.com/u/giom)\
**Post date:** [December 27, 2005, 11:40pm UTC](https://www.ruby-forum.com/t/gem-and-ruby-extension/51193/3 "2005-12-27T23:40:40Z")

</div>

On Wed, 2005-12-28 at 06:33 +0900, Jim W. wrote:

> Guillaume M. wrote:
> 
> > Duh! Why can’t it load rulog.so in the first case? The platform is ruby  
> > 1.8.2 (2004-12-25) [i586-linux-gnu].
> 
> Ruby is able to find libraries installed via RubyGems only after the  
> rubygem library is loaded. You can accomplish in several ways,  
> including setting an environment variable (RUBYOPT=rubygems), including  
> -rubygems on your ruby command line, or even putting a ‘require  
> “rubygems”’ in your source code. See  
> [http://docs.rubygems.org/read/chapter/3#page70](http://docs.rubygems.org/read/chapter/3#page70) for details.

Thanks for you quick answer. But I forgot to mention that I already have  
the RUBYOPT variable set:

[gus@comp ruby-1.8.2]$ echo $RUBYOPT  
-rrubygems  
[gus@comp ruby-1.8.2]$ grep RUBY ~/.bashrc  
RUBYOPT=“-rrubygems”  
export RUBYOPT

What strikes me as odd in this case is that it gives the right path of  
the library to load (somewhere in /usr/lib/ruby/gems) but fails to load  
it. If the path is added to $: (in the second example), then it loads  
properly.

Guillaume.

---

<div class="post-metadata">

**Author:** ![giom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/e56c9b/32.png) [@giom](https://www.ruby-forum.com/u/giom)\
**Post date:** [December 28, 2005, 2:20am UTC](https://www.ruby-forum.com/t/gem-and-ruby-extension/51193/4 "2005-12-28T02:20:11Z")

</div>

On Wed, 2005-12-28 at 09:47 +0900, Une bévue wrote:

> BEWARE, in your case you have TWO “r” ie :  
> -rrubygems

Actually, both work. AFAIK, rubygems is the official name of the library  
but ubygems is also there so it looks good when using the -r options.  
‘ruby -rubygems’ and ‘ruby -rrubygems’ are equivalent.

Looking in /usr/lib/ruby I see:

/usr/lib/ruby/site\_ruby/1.8/ubygems.rb  
/usr/lib/ruby/site\_ruby/1.8/rubygems.rb

and

$ cat /usr/lib/ruby/site\_ruby/1.8/ubygems.rb

# This file allows for the running of rubygems with a nice

# command line look-and-feel: ruby -rubygems foo.rb

require ‘rubygems’

Guillaume.

---

<div class="post-metadata">

**Author:** ![giom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/e56c9b/32.png) [@giom](https://www.ruby-forum.com/u/giom)\
**Post date:** [December 28, 2005, 1:50am UTC](https://www.ruby-forum.com/t/gem-and-ruby-extension/51193/5 "2005-12-28T01:50:03Z")

</div>

Guillaume M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> [gus@comp ruby-1.8.2]$ echo $RUBYOPT  
> -rrubygems

do you think this is right, because i’ve done :  
export RUBYOPT=rubygems  
(without de “-”)  
and, i’ve seen progs complaining about ubygems (without the “r”)

BEWARE, in your case you have TWO “r” ie :  
-rrubygems  
_^^_\_\_\_\_\_\_

---

<div class="post-metadata">

**Author:** ![giom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/e56c9b/32.png) [@giom](https://www.ruby-forum.com/u/giom)\
**Post date:** [December 28, 2005, 1:44am UTC](https://www.ruby-forum.com/t/gem-and-ruby-extension/51193/6 "2005-12-28T01:44:03Z")

</div>

On Wed, 2005-12-28 at 07:38 +0900, Guillaume M. wrote:

> > [http://docs.rubygems.org/read/chapter/3#page70](http://docs.rubygems.org/read/chapter/3#page70) for details.  
> > What strikes me as odd in this case is that it gives the right path of  
> > the library to load (somewhere in /usr/lib/ruby/gems) but fails to load  
> > it. If the path is added to $: (in the second example), then it loads  
> > properly.

My fault. rb\_mark doesn’t exists, rb\_gc\_mark is want I wanted. What  
confused me is that it doesn’t complain when the library is required,  
but when the call of this function is made.

Sorry for the noise,  
Guillaume.

---

<div class="post-metadata">

**Author:** ![giom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/e56c9b/32.png) [@giom](https://www.ruby-forum.com/u/giom)\
**Post date:** [December 28, 2005, 8:54am UTC](https://www.ruby-forum.com/t/gem-and-ruby-extension/51193/7 "2005-12-28T08:54:08Z")

</div>

Guillaume M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Actually, both work. AFAIK, rubygems is the official name of the library  
> but ubygems is also there so it looks good when using the -r options.  
> ‘ruby -rubygems’ and ‘ruby -rrubygems’ are equivalent.

thanks for your input that makes my setup clearer to me ))  
my prob with “ubygems” comes to the fact i’ve two Rubys :  
the default install on MacOS X /usr/bin/ruby  
and the darwinports one /opt/local/bin/ruby  
only the latest works with rubygems…
