# Ruby extension (C++) on OS X and Google-Sketchup \[ruby 1.8.5

**URL:** <https://www.ruby-forum.com/t/ruby-extension-c-on-os-x-and-google-sketchup-ruby-1-8-5/83575>\
**Category:** Ruby\
**Created:** [January 27, 2007, 3:50am UTC](https://www.ruby-forum.com/t/ruby-extension-c-on-os-x-and-google-sketchup-ruby-1-8-5/83575 "2007-01-27T03:50:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nicholas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/4da419/32.png) [@Nicholas](https://www.ruby-forum.com/u/Nicholas)\
**Post date:** [January 27, 2007, 3:50am UTC](https://www.ruby-forum.com/t/ruby-extension-c-on-os-x-and-google-sketchup-ruby-1-8-5/83575/1 "2007-01-27T03:50:45Z")

</div>

Hi,

I have written a ruby extension in C++ and it works fine on OS X  
Tiger which ships ruby-1.8.2.

With the succesful test of the extension (bundle), I then proceed to  
try to use it within Google-Sketchup [which I think embeds ruby-1.8.5].

Sketchup crashes the application just loading the extension.

8\<------8\<------8\<------8\<------8\<------8\<------8\<------8\<------8\<------  
void  
Init\_rcl(void)  
{  
cRCL = rb\_define\_class(“rcl”, rb\_cObject); \<=== /CRASH  
8\<------8\<------8\<------8\<------8\<------8\<------8\<------8\<------8\<------

Has there been significant changes in extension loading/startup  
between ruby 1.8.2 and 1.8.5?

I could install 1.8.5 on my machine to try ou but wanted to find out  
more information before I do that.

Regards

---

<div class="post-metadata">

**Author:** ![Nicholas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/4da419/32.png) [@Nicholas](https://www.ruby-forum.com/u/Nicholas)\
**Post date:** [January 27, 2007, 11:23am UTC](https://www.ruby-forum.com/t/ruby-extension-c-on-os-x-and-google-sketchup-ruby-1-8-5/83575/2 "2007-01-27T11:23:17Z")

</div>

On Jan 26, 2007, at 6:50 PM, Nicholas wrote:

> ## 8\<------8\<------8\<------8\<------8\<------8\<------8\<------8\<------8\<----
> 
> ## void Init\_rcl(void) { cRCL = rb\_define\_class(“rcl”, rb\_cObject); \<=== /CRASH 8\<------8\<------8\<------8\<------8\<------8\<------8\<------8\<------8\<----

That could should be fine in pretty much any version of ruby.

> Has there been significant changes in extension loading/startup  
> between ruby 1.8.2 and 1.8.5?

nope, but if you compiled and linked against one version (1.8.2) I  
don’t think you can count on it working in binary form on another  
version, ESPECIALLY the stock 1.8.2 that ships on osx (unless apple  
has fixed up their stuff).

I’m not positive, but I think even if you do recompile it on 1.8.5 it  
could still be unstable because they could compile and link in the  
embedded ruby entirely different from yours. You could either  
refactor all your external code out to a generic dynamic library  
(a .bundle on osx) and write pure ruby DL code that calls out to it  
(I dunno if that is an option with sketchup or not), or you could  
possibly try out rubyinline so the compile and link happens the same  
as with sketchup’s embedded interp. Again, dunno if that will work  
with sketchup.

---

<div class="post-metadata">

**Author:** ![Nicholas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/4da419/32.png) [@Nicholas](https://www.ruby-forum.com/u/Nicholas)\
**Post date:** [January 27, 2007, 9:52pm UTC](https://www.ruby-forum.com/t/ruby-extension-c-on-os-x-and-google-sketchup-ruby-1-8-5/83575/3 "2007-01-27T21:52:47Z")

</div>

Nicholas wrote:

> I have written a ruby extension in C++ and it works fine on OS X  
> Tiger which ships ruby-1.8.2.

I’m surprised that it actually works in 1.8.2…

> ```
> cRCL = rb_define_class("rcl", rb_cObject); <=== /CRASH
> 
> ```

Why are you defining a class whose name is not capitalized?

Ruby doesn’t let you do this from Ruby code:

$ irb  
class rcl  
end  
SyntaxError: compile error  
(irb):1: class/module name must be CONSTANT  
from (irb):2

---

<div class="post-metadata">

**Author:** ![Nicholas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/4da419/32.png) [@Nicholas](https://www.ruby-forum.com/u/Nicholas)\
**Post date:** [January 28, 2007, 2:49am UTC](https://www.ruby-forum.com/t/ruby-extension-c-on-os-x-and-google-sketchup-ruby-1-8-5/83575/4 "2007-01-28T02:49:09Z")

</div>

On Jan 27, 2007, at 12:52 PM, Suraj K. wrote:

> Nicholas wrote:
> 
> > I have written a ruby extension in C++ and it works fine on OS X  
> > Tiger which ships ruby-1.8.2.
> 
> I’m surprised that it actually works in 1.8.2…

Why? Nothing has fundamentally changed since 1.8.2. His code sample  
should work in 1.6 just fine as well.

> > ```
> > cRCL = rb_define_class("rcl", rb_cObject); <=== /CRASH
> > 
> > ```
> 
> Why are you defining a class whose name is not capitalized?

That has nothing to do with why he’s crashing.

> Ruby doesn’t let you do this from Ruby code:
> 
> $ irb  
> class rcl  
> end  
> SyntaxError: compile error  
> (irb):1: class/module name must be CONSTANT  
> from (irb):2

% ruby -e ‘names = []; ObjectSpace.each\_object(Module) { |o| names \<\<  
o.name if o.name =~ /^[a-z]/ }; p names’  
[“fatal”]
