# Bug on Ruby extension

**URL:** <https://www.ruby-forum.com/t/bug-on-ruby-extension/180253>\
**Category:** Ruby\
**Created:** [December 15, 2009, 10:32pm UTC](https://www.ruby-forum.com/t/bug-on-ruby-extension/180253 "2009-12-15T22:32:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![denommus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e99b99/32.png) [@denommus](https://www.ruby-forum.com/u/denommus)\
**Post date:** [December 15, 2009, 10:32pm UTC](https://www.ruby-forum.com/t/bug-on-ruby-extension/180253/1 "2009-12-15T22:32:10Z")

</div>

I’m trying to make a glue code for ODE 0.9 on Ruby 1.8.7. This is my  
code:

#include “ruby.h”  
#include “ode/ode.h”

VALUE ode\_init(VALUE self)  
{  
dWorldID mWorldID = dWorldCreate();  
rb\_iv\_set(self, “@world”, (VALUE)mWorldID);  
return self;  
}

VALUE ode\_destroy(VALUE self)  
{  
mWorldID = (dWorldID)rb\_iv\_get(self, “@world”)  
dWorldDestroy(mWorldID);  
rb\_iv\_set(self, “@world”, Qnil);  
return Qnil  
}

VALUE cOde;

void Init\_Cegui()  
{  
cCegui = rb\_define\_class(“Ode”, rb\_cObject);  
rb\_define\_method(cOde, “initialize”, ode\_init, 0);  
rb\_define\_method(cOde, “destroy”, ode\_destroy, 0);  
}

This is my extconf.rb:

require ‘mkmf’  
dir\_config(“ODE”, “/media/disk/yuri/ode-0.9”)  
have\_library(“ode”)  
create\_makefile(‘example’)

This is my output:

cc -I. -I. -I/usr/lib/ruby/1.8/i486-linux -I.  
-I/media/disk/yuri/ode-0.9/include -D\_FILE\_OFFSET\_BITS=64 -fPIC  
-fno-strict-aliasing -g -g -O2 -fPIC -c example.c  
In file included from /media/disk/yuri/ode-0.9/include/ode/ode.h:28,  
from example.c:2:  
/media/disk/yuri/ode-0.9/include/ode/config.h:192:1: warning:  
“PACKAGE\_BUGREPORT” redefined  
In file included from /usr/lib/ruby/1.8/i486-linux/ruby.h:24,  
from example.c:1:  
/usr/lib/ruby/1.8/i486-linux/config.h:5:1: warning: this is the location  
of the previous definition  
In file included from /media/disk/yuri/ode-0.9/include/ode/ode.h:28,  
from example.c:2:  
/media/disk/yuri/ode-0.9/include/ode/config.h:195:1: warning:  
“PACKAGE\_NAME” redefined  
In file included from /usr/lib/ruby/1.8/i486-linux/ruby.h:24,  
from example.c:1:  
/usr/lib/ruby/1.8/i486-linux/config.h:1:1: warning: this is the location  
of the previous definition  
In file included from /media/disk/yuri/ode-0.9/include/ode/ode.h:28,  
from example.c:2:  
/media/disk/yuri/ode-0.9/include/ode/config.h:198:1: warning:  
“PACKAGE\_STRING” redefined  
In file included from /usr/lib/ruby/1.8/i486-linux/ruby.h:24,  
from example.c:1:  
/usr/lib/ruby/1.8/i486-linux/config.h:4:1: warning: this is the location  
of the previous definition  
In file included from /media/disk/yuri/ode-0.9/include/ode/ode.h:28,  
from example.c:2:  
/media/disk/yuri/ode-0.9/include/ode/config.h:201:1: warning:  
“PACKAGE\_TARNAME” redefined  
In file included from /usr/lib/ruby/1.8/i486-linux/ruby.h:24,  
from example.c:1:  
/usr/lib/ruby/1.8/i486-linux/config.h:2:1: warning: this is the location  
of the previous definition  
In file included from /media/disk/yuri/ode-0.9/include/ode/ode.h:28,  
from example.c:2:  
/media/disk/yuri/ode-0.9/include/ode/config.h:204:1: warning:  
“PACKAGE\_VERSION” redefined  
In file included from /usr/lib/ruby/1.8/i486-linux/ruby.h:24,  
from example.c:1:  
/usr/lib/ruby/1.8/i486-linux/config.h:3:1: warning: this is the location  
of the previous definition  
example.c: In function â€˜ode\_destroyâ€™:  
example.c:13: error: â€˜mWorldIDâ€™ undeclared (first use in this function)  
example.c:13: error: (Each undeclared identifier is reported only once  
example.c:13: error: for each function it appears in.)  
example.c:14: error: expected â€˜;â€™ before â€˜dWorldDestroyâ€™  
example.c:17: error: expected â€˜;â€™ before â€˜}â€™ token  
example.c: In function â€˜Init\_Ceguiâ€™:  
example.c:23: error: â€˜cCeguiâ€™ undeclared (first use in this function)  
make: \*\* [example.o] Erro 1

I think it’s a conflict between ode/config.h and config.h, but I have no  
idea how to solve. My Ruby version is ruby 1.8.7 (2008-08-11 patchlevel  
72) [i486-linux] and I’m on Ubuntu 9.04.

---

<div class="post-metadata">

**Author:** ![denommus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e99b99/32.png) [@denommus](https://www.ruby-forum.com/u/denommus)\
**Post date:** [December 15, 2009, 11:11pm UTC](https://www.ruby-forum.com/t/bug-on-ruby-extension/180253/2 "2009-12-15T23:11:36Z")

</div>

> example.c: In function â€˜ode\_destroyâ€™:  
> example.c:13: error: â€˜mWorldIDâ€™ undeclared (first use in this function)

Spot the difference between line 6 and line 13 of your code.

Hint: in C, you must declare a variable’s type before you can use it.

> example.c: In function â€˜Init\_Ceguiâ€™:  
> example.c:23: error: â€˜cCeguiâ€™ undeclared (first use in this function)

Ditto.

---

<div class="post-metadata">

**Author:** ![denommus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e99b99/32.png) [@denommus](https://www.ruby-forum.com/u/denommus)\
**Post date:** [December 15, 2009, 11:18pm UTC](https://www.ruby-forum.com/t/bug-on-ruby-extension/180253/3 "2009-12-15T23:18:22Z")

</div>

Oh, gosh, I didn’t even attempted to this. I thought it was conflict  
error.

Well, I corrected the code and now it is compiling (although it has some  
warnings because of the conflicts). Thank you very much.
