# .rb file includes c-extension of same name?

**URL:** <https://www.ruby-forum.com/t/rb-file-includes-c-extension-of-same-name/55343>\
**Category:** Ruby\
**Created:** [March 20, 2006, 3:40am UTC](https://www.ruby-forum.com/t/rb-file-includes-c-extension-of-same-name/55343 "2006-03-20T03:40:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kelleysislander](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f6c823/32.png) [@kelleysislander](https://www.ruby-forum.com/u/kelleysislander)\
**Post date:** [March 20, 2006, 3:40am UTC](https://www.ruby-forum.com/t/rb-file-includes-c-extension-of-same-name/55343/1 "2006-03-20T03:40:13Z")

</div>

Hi,

I have foo.rb and foo.so, the C-extension part of the module.

Inside foo.rb, I can put, require ‘foo.so’, and it works fine,  
allowing other modules to say require ‘foo’, and have the .rb  
be loaded, which in turn loads the C-extension.

I’m wondering if there’s a recommended platform-independent  
way to do this? For instance, on OS X, C-extensions end in  
“.bundle” not “.so”.

I wouldn’t mind even saying require “foo.#{DLEXT}”, if there  
were such a thing available from ruby.

Is there a recommended way to have a .rb file require a  
C-extension file of the same name in a platform-independent  
way? Or is the preferred solution to alter the name of one  
of the two files?

Thanks,

Bill

---

<div class="post-metadata">

**Author:** ![kelleysislander](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f6c823/32.png) [@kelleysislander](https://www.ruby-forum.com/u/kelleysislander)\
**Post date:** [March 20, 2006, 6:24am UTC](https://www.ruby-forum.com/t/rb-file-includes-c-extension-of-same-name/55343/2 "2006-03-20T06:24:30Z")

</div>

On Mon, 20 Mar 2006, Bill K. wrote:

> “.bundle” not “.so”.  
> Thanks,
> 
> Bill

harp:~ \> ruby -r yaml -r rbconfig -e’ y Config::CONFIG '|egrep DLEXT  
DLEXT2: “”  
DLEXT: so

-a

---

<div class="post-metadata">

**Author:** ![kelleysislander](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f6c823/32.png) [@kelleysislander](https://www.ruby-forum.com/u/kelleysislander)\
**Post date:** [March 20, 2006, 6:41am UTC](https://www.ruby-forum.com/t/rb-file-includes-c-extension-of-same-name/55343/3 "2006-03-20T06:41:34Z")

</div>

From: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> harp:~ \> ruby -r yaml -r rbconfig -e’ y Config::CONFIG '|egrep DLEXT  
> DLEXT2: “”  
> DLEXT: so

Aha! TYVM. I’d been grepping the C source. . . .

Regards,

Bill

---

<div class="post-metadata">

**Author:** ![kelleysislander](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f6c823/32.png) [@kelleysislander](https://www.ruby-forum.com/u/kelleysislander)\
**Post date:** [March 20, 2006, 1:18pm UTC](https://www.ruby-forum.com/t/rb-file-includes-c-extension-of-same-name/55343/4 "2006-03-20T13:18:54Z")

</div>

Bill K. wrote:

> “.bundle” not “.so”.  
> Thanks,
> 
> Bill

You can just always use “.so”. Ruby is clever enough to figure out what  
“.so” really means on the current platform.

---

<div class="post-metadata">

**Author:** ![kelleysislander](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f6c823/32.png) [@kelleysislander](https://www.ruby-forum.com/u/kelleysislander)\
**Post date:** [March 20, 2006, 11:19am UTC](https://www.ruby-forum.com/t/rb-file-includes-c-extension-of-same-name/55343/5 "2006-03-20T11:19:00Z")

</div>

“Bill K.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

> “.bundle” not “.so”.  
> Thanks,
> 
> Bill

An alternative: call the C bit “foo\_ext.so” (say) and then in “foo.rb”  
just do “require ‘foo\_ext’”?
